- Home /
Question by
smtabatabaie · Sep 02, 2013 at 08:19 PM ·
buttontouchtoggle button
GameObject as toggle button with touch
I'm trying to make a gameobject as a toggle button which works with touch. here's my code which works but there's a problem. if you don't release your finger from screen the toggle button keeps toggling . I'm looking for something like "OnMouseRelease" function.
function FixedUpdate()
{
if(Input.touchCount>0)
{
var theTouch : Touch = Input.GetTouch(0);
var ray = Camera.main.ScreenPointToRay(theTouch.position);
if(Physics.Raycast(ray,hit,500000,layerMask))
{
if(Input.touchCount==1)
{
var hitTag = hit.transform.tag;
if(hit.transform.CompareTag("toggleBtn")
{
//do actions
}
}
}
}
}
I tried to embrace it with a condition of TouchPhase.Began but it didn't work either . I also tried to add a boolean as a condition and make it active by a delay with yield but it didn't work either.
Comment
Best Answer
Answer by ArkaneX · Sep 02, 2013 at 09:20 PM
TouchPhase.Began should work. Could you test it in Update instead of FixedUpdate?
And please take a look at this question.
Thanks , I think the problem was using FixedUpdate ins$$anonymous$$d of Update . I'm still experimenting on this subject
Your answer