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

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
alaja
Posts: 1
Joined: Thu Apr 21, 2016 9:10 pm

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

Post by alaja »

Ii wonder if it is possible to play a movie texture when the npc response in the dialog?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

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

Post 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.
Post Reply