- Home /
GameObject touchable instead GUI button
i have this
if( GUI.Button( new Rect( xPos, yPos, width, height ), "Start Video Texture Two" ) )
{
// create the video texture
_videoTextureTwo = new VideoTexture( "skyfall.m4v", 480, 264, false, 0, true );
}
i want to make instead a GUI button make a GameObject for example an cube touchable, and send this star video blab la. so. . what do i can do for it?
please help im stock
Answer by silverdreamx · Nov 08, 2012 at 07:11 AM
You can add a Collider component to your GameObject. Then, to check for touch on the object, on the Update() function of your GameObject, do a RaycastHit test like below:
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (collider.Raycast(ray, out hitInfo, 1.0e8f))
{
if (!Physics.Raycast(ray, hitInfo.distance - 0.01f))
{
// do your button handling here
}
}
Hope this is helpful!
HI, THAN$$anonymous$$S FOR ANSWER, BUT THIS CODE IS C++??
THE CODE THAT I NEE TO PUT IS THIS.
IN THE CODE TAHT YOU POST, WHERE DO I PUT THE GA$$anonymous$$EOBJECT NA$$anonymous$$E OR HOW TO DIRECT THE FUNCTION TO THIS EXACT GA$$anonymous$$EOBJECT.
PLEASE HELP.
// create the video texture _videoTextureTwo = new VideoTexture( "skyfall.m4v", 640, 360, false, 0, true ); // apply the texture to a material and set the UVs targetTwo.renderer.shared$$anonymous$$aterial.mainTexture = _videoTextureTwo.texture; LiveTextureBinding.update$$anonymous$$aterialUVScaleForTexture( targetTwo.renderer.shared$$anonymous$$aterial, _videoTextureTwo.texture ); // add some event handlers _videoTextureTwo.videoDidStartEvent = () => { Debug.Log( "Video two started" ); }; _videoTextureTwo.videoDidFinishEvent = () => { // when the video finishes if we are not set to loop this instance is no longer valid and this texture is not set to loop _videoTextureTwo = null; Debug.Log( "Video two finished" ); };
Sorry for the late reply... The code is in C# unity script.
I'm not sure how you are doing this, but if you want an additional button, you will have to create a new game object for the button. To do the collision detection for the button game object, attach a Collider component to the button game object, and then add the Update function mentioned above. The button will then be separate from where you create the video texture, though your event handling will need to be done in the button.
Answer by octaviomejiadiaz · Nov 08, 2012 at 04:29 PM
but this is not C++ isnt ?
sorry im new on this, this is the code C++ that i want to change : i have to change all this to a touchable GameObject :
if( GUI.Button( new Rect( xPos, yPos, width, height ), "Start Video Texture Two" ) ) { // create the video texture _videoTextureTwo = new VideoTexture( "skyfall.m4v", 640, 360, false, 0, true ); // apply the texture to a material and set the UVs targetTwo.renderer.sharedMaterial.mainTexture = _videoTextureTwo.texture; LiveTextureBinding.updateMaterialUVScaleForTexture( targetTwo.renderer.sharedMaterial, _videoTextureTwo.texture ); // add some event handlers _videoTextureTwo.videoDidStartEvent = () => { Debug.Log( "Video two started" ); }; _videoTextureTwo.videoDidFinishEvent = () => { // when the video finishes if we are not set to loop this instance is no longer valid and this texture is not set to loop _videoTextureTwo = null; Debug.Log( "Video two finished" ); }; }
Please heeeeeelp i so stock
Your answer
Follow this Question
Related Questions
Char select / GUI button question. 3 Answers
Detect Click on Gameobject 0 Answers
How do I make individual buttons change individual variables? 0 Answers
Cube click pop-up menu 0 Answers