- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
Nabil_fx · Nov 15, 2014 at 05:40 PM ·
Touch Gui button
How can i change this Object touch button, to a GUItexture touch button.
function Update () {
for(var i:int = 0; i < Input.touches.Length; i++)//How many touches do we have?
{
var touch:Touch = Input.touches[i];//The touch
var ray:Ray = Camera.main.ScreenPointToRay(touch.position);
var hit:RaycastHit = new RaycastHit();
if(Physics.Raycast(ray,hit, 1000))
{
if(hit.collider.gameObject == this.gameObject)
{
switch(touch.phase)
{
case TouchPhase.Began://if the touch begins
Application.LoadLevel("CENA2 ");
break;
}
}
}
}
}
Comment
Answer by robertbu · Nov 15, 2014 at 05:45 PM
OnMouseDown() works with touch and GUITextures, so you can do:
function OnMouseDown() {
Application.LoadLevel("CENA2 ");
}
If you want to use your current code, you can use GUITexture.HitTest() instead of Physics.Raycast().
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Animation Not Playing 1 Answer
3D Gravity towards one object 3 Answers
How do i put lights with muzzleflash? 1 Answer
How to Load from an external file, sound 0 Answers