Page 1 of 1

Is posible add a MovieTexture as a varible and play it using lua?

Posted: Thu Apr 21, 2016 9:20 pm
by alaja
Ii wonder if it is possible to play a movie texture when the npc response in the dialog?

Re: Is posible add a MovieTexture as a varible and play it using lua?

Posted: Thu Apr 21, 2016 10:42 pm
by Tony Li
Sure. Write a C# method to play the movie texture, and then register it with Lua. For example:

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class LuaMoviePlayer : MonoBehaviour {

    public MovieTexture[] movieTextures; // Array of movies.
    private MovieTexture currentMovieTexture;

    void OnEnable() {
        Lua.RegisterFunction("PlayMovie", this, SymbolExtensions.GetMethodInfo(() => PlayMovie((int) 0)));
    }
        
    void OnDisable() {
        Lua.UnregisterFunction("PlayMovie");
    }
        
    public void PlayMovie(int i) {
        currentMovieTexture = movieTextures[i];
        GetComponent<Renderer>().material.mainTexture = currentMovieTexture;
        currentMovieTexture.Play();
        Invoke("StopMovie", 1); // Stop playing after 1 second.
    }
    
    public void StopMovie() {
        currentMovieTexture.Stop();
    }
}
In your dialogue entry node, put something like this in the Script field:
  • Script: PlayMovie(3)
If you want to play a unique movie for each dialogue entry, you could write a custom sequencer command instead, and use entrytags.

Or just add a script to the Dialogue Manager that has an OnConversationLine() method, and play the movie in this method.

Let me know if you'd like more details on any of these methods.