c# - desible GetTouch after 1st touch -
i have object want throw @ distance gettouch.my code working problem when touch screen multiple time,the object move multiple time dont want,i want object move 1 time no matter how many time touch or swipe screen.here's tried.
public class realballmove : monobehaviour { public float speed; public rigidbody rb; void start() { rb = getcomponent<rigidbody>(); } void update() { if (input.touchcount >0 && input.gettouch(0).phase == touchphase.ended || (input.getmousebuttondown(0))) { //rb.addforce(vector3.forward * speed); //rb.addforce(vector3.up * speed); getcomponent<rigidbody> ().iskinematic = false; getcomponent<rigidbody> ().addforce (new vector3(0.0f, 20.0f, 12.0f)); //destroy (getcomponent<rigidbody>()); }
} }
simply add boolean indicating whether have thrown ball ;)
public class realballmove : monobehaviour { public float speed; public rigidbody rb; private bool thrown ; void start() { rb = getcomponent<rigidbody>(); } void update() { if ( !thrown && ( (input.touchcount > 0 && input.gettouch(0).phase == touchphase.ended ) || input.getmousebuttondown(0) ) ) { rb.iskinematic = false; rb.addforce (new vector3(0.0f, 20.0f, 12.0f)); thrown = true ; } } }
an other option disable script when touch detected, if script lines above , nothing else.
Comments
Post a Comment