- Home /
Play a video ingame by clickin on gameobject
All is in the title :) I just search how to play an video when i click with the mouse on an gameobject and put it in pause when i re click on the same ( or other ) game object .
I'm very bad at scripting and here is where i am with the script ^^ :)
var PlayButton : GameObject;
function OnMouseDown () {
renderer.material.mainTexture.Play();
}
Thanks for helping
Answer by snedgel · Mar 05, 2013 at 01:02 PM
Doesn't work .... On what i have to click to start the video ?
Answer by 3dws · Mar 05, 2013 at 10:47 AM
do you import your video clip in unity and assign it to material of the object? do you know that u must use the Quicktime movie clips in unity3d? if not , u must convert it in .mov clip
I have a .mov ;)
I have no problem to run the video with
renderer.material.mainTexture.Play();
But i want to click to a specific gameobject to run the video
ok u must use 2 object . 1 for move texture (movie object) and other for Play Button .
U must create 1 script for play button and in it u must access to movie object .
u can use this code on Play Buttonobject:
var move : GameObject;
function start(){
move= GameObject.Find("movieobject");
// now u can access to movie object
}
function On$$anonymous$$ouseDown () {
if (move.renderer.material.mainTexture.isPlaying) {
move.renderer.material.mainTexture.Pause();
}
else {
move.renderer.material.mainTexture.Play();
}
}
Thanks, it works :)
But now i have an another problem . $$anonymous$$y video start when i press the playmode ... I just want to play the video when i click on the Gameobject " PlayButton" .
Is the PlayButton a separate Object? If so drop the start function and assign the movie using the inspector. If not so split the original mesh in two or more parts..
Answer by fabio1955 · Mar 05, 2013 at 02:03 PM
On mousedown will work on the object the script is attached to. Did you attach the script to some object? Just asking because you said you are "very bad at scripting"...
Your answer
Follow this Question
Related Questions
pause game 2 Answers
Unity android button and Time.timescale problems 1 Answer
A node in a childnode? 1 Answer
GUITexture OnMouseDown Problem 1 Answer