I. Jones
I. Jones

Reputation: 151

Why isn't my for each loop working in Unity?

Right now I am just trying to detect when the person touches the screen but I keep getting an error saying: error CS1525: Unexpected symbol :', expecting)', ,',;', [', or='. The rest of the code may not be right either, but I can't get the for each loop to work and I can't figure it out.

    for (var touch: Touch in Input.touches) {
        if(touch.phase == TouchPhase.Began)
            Move(new Vector3(0, 0, 1));
    }

Upvotes: 1

Views: 781

Answers (1)

meganaut
meganaut

Reputation: 503

in C# you need to use the keyword foreach for enumerating over a list like that:

i.e.

foreach (var touch in Input.touches) {
        if(touch.phase == TouchPhase.Began)
            Move(new Vector3(0, 0, 1));
    }

Edit:

I used what was on the unity website and I thought this would be accurate and I am pretty new

You can select C# or Javascript on Unity Reference website. If you select C#, you will get C# sample code. You got the code in your question because you selected Javascript .

enter image description here

Upvotes: 7

Related Questions