- Home /
Trying to make a video triggerable by a button.
I can make the video play with this script:
var movieFile : MovieTexture;
function OnTriggerEnter (col : Collider) {
//This gets called when the player hits the movie plane
if (col.gameObject.name.StartsWith("Player")) { //Check that we are dealing with the player.
renderer.material.mainTexture = movieFile; // Assign the movie to the renderer.
movieFile.Play(); //Play the movie on the plane
}
}
The problem I am having is I can't figure out how to make a separate collider like a button make the video start. My ultimate goal is to have three buttons which can cause different videos to play on a screen.
read up about OnTriggerEnter scripts, there should be dozens and dozens of varied and illustrative example scripts available for you to learn and copy from in the OnTriggerEnter questions on this forum
Answer by FirePlantGames · Oct 31, 2013 at 02:34 AM
so I don't know if this is what you want but to me it sounds that: you have a player and when he runs into a trigger collider and then a movie should play if that is the case then try this:
var movieFile : MovieTexture;
function OnTriggerEnter (col : Collider)
{
if (col.transform.name("Player"))// you can also use a tag sytem
{
renderer.material.mainTexture = movieFile;
movieFile.Play();
}
}
(please note that i have never used movieTextures before)
very sorry i didn't read very properly,okay,so say your button is on a wall, have a trigger collider in front of that button, then have this script on that trigger object(the script is untested): var movieFile : $$anonymous$$ovieTexture;
function OnTriggerStay (col : Collider)
{
if (col.transform.name("Player") && Input.GetButtonDown("Action"))
{
renderer.material.mainTexture = movieFile;
movieFile.Play(); //Play the movie on the plane
}
}
*the action button is a example Input this can be anything for example: Fire1(left button on the mouse if you have default input settings.)
make a separate collider like a button ... 3d buttons rather than keyboard ones. i.e. 3 cylinders
Your answer
Follow this Question
Related Questions
Trigger sound when pressing button 2 Answers
Sprite Animation using mouse, like an interactive ebook 0 Answers
Hitting one trigger activates all triggers? 1 Answer
How do i make a button appear when my FPSController walks through a tigger collider? 4 Answers
How do I make a button appear when my player enters a trigger? 1 Answer