Why is i zero in debug?

Not sure why the int i which i am using for loop stays at zero in debug. The code is working of a fashion (the object tree is scaling up) but i am a bit confused why. Thanks very any help.

using UnityEngine;
using System.Collections;
using System;
public class Treegrowth : MonoBehaviour
{

int treeScale = 10;
public Vector3 scale = new Vector3 (1,1,1);
int i = 0;

// Use this for initialization

void Start ()
{

for ( int i = 3; i < treeScale; i++, scale.x++,scale.y++ , scale.z++);

{
transform.localScale += new Vector3 (scale.x, scale.y, scale.z);

// Console.WriteLine(i);

Debug.Log("I is: " + i);
}
}

// Update is called once per frame
void Update ()
{

}
}

You have a semicolon after your for statement.

Please use code blocks next time to make the code easier to read.

2 Likes

You also have two int i variables, in the loop you make a new one that doesn’t update the one in global scope you see while debugging inspector.

1 Like

Thanks guys, I only put the second int variable in when testing so that error was not causing the initial problem - removing the semicolon did the trick.