- Home /
foreach (Touch touch in Input.touches) not working
Hey guys, I am trying to use a foreach loop for the menus. I am getting this error: error CS0030: Cannot convert type UnityEngine.Touch' to
Touch'
Any ideas? Works fine in UnityScript but not in C#
Thanks :)
Here is the section of my script:
foreach (Touch touch in Input.touches) {
//Button1
if (touch.phase == TouchPhase.Stationary && btn1.HitTest (touch.position) || touch.phase == TouchPhase.Moved && btn1.HitTest (touch.position))
{
//Change colour when pressed
btn1.guiTexture.color = colorEnd;
}
else if (touch.phase == TouchPhase.Ended && btn1.HitTest (touch.position) && touch.phase != TouchPhase.Canceled)
{
if(playSound) AudioSource.PlayClipAtPoint(clickSound, transform.position);
//do whatever
}
}
Comment
Best Answer
Answer by Statement · Dec 28, 2013 at 02:00 PM
You probably have written your own Touch class so you are getting name conflicts.
Try this to resolve the ambiguitiy:
foreach (UnityEngine.Touch touch in Input.touches)
Or this:
foreach (var touch in Input.touches)
Maybe you have a script or a type called Touch. Perhaps it's even the name of the script which your problematic code lives in.
Thank you, I would have never thought of this. I had another class called Touch. All fixed now!
Thank you again!