- Home /
Touch Phase ended not executing
I have three buttons on screen 'UP_KEY', 'RIGHT_KEY' and 'LEFT_KEY' I need to be able to touch these three buttons at the same time and be able to hold 'RIGHT_KEY' and 'LEFT_KEY' to make the player continuously move left or right.
I have used this to detect a touch but I can't seem to get the TouchPhase.Ended to execute
void Update () {
foreach (Touch touch in Input.touches)
if (touch.phase == TouchPhase.Stationary)
ray = Camera.main.ScreenPointToRay (touch.position);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray,out hit,1000.0f))
if(hit.collider.gameObject == this.gameObject)
moveplayerRight = 1;
foreach (Touch touch in Input.touches)
if (touch.phase == TouchPhase.Ended)
moveplayerRight = 0;
Have I donE something drastically wrong? I have only been doing this for a week now and I can't wrap my head around these touch controls.e
Comment
Best Answer
Answer by Ashutosh8126 · Sep 08, 2013 at 07:21 AM
You u don't need to make.. two loops.. actually the problem.. when u r making a new Loop.. Itz looking for the touch end phase for the first touch... Use this instead..
foreach (Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Stationary)
ray = Camera.main.ScreenPointToRay (touch.position);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray,out hit,1000.0f))
if(hit.collider.gameObject == this.gameObject)
moveplayerRight = 1;
if (touch.phase == TouchPhase.Ended)
moveplayerRight = 0;
}