I have 2 scripts: Score.cs and Scoring.cs. When the public static int iScore is updated in Scoring.cs during void Start (), the variable does not change in Score.cs, although it is fine during void Update ().
Score.cs:
public class Score : MonoBehaviour
{
public Text textbox;
void Start()
{
textbox = GetComponent<Text>();
}
void Update()
{
textbox.text = "Score: " + Scoring.iScore;
Debug.Log (Scoring.iScore);
}
}
Scoring.cs:
public static int iScore;
private bool bBelow;
void Start ()
{
iScore = 0;
Debug.Log ("Start" + iScore);
bBelow = false;
Vector3 Pos = Movement2.Position;
this.transform.position = new Vector3 (Random.Range(-2, 2), this.transform.position.y);
}
void Update ()
{
float fPosition = gameObject.transform.position.y;
Vector3 Pos = Movement2.Position;
if (Pos.y < this.transform.position.y && bBelow == false)
{
iScore = iScore + 1;
bBelow = true;
}
if (fPosition >= 6)
{
//Move back to starting position
this.transform.position = new Vector3 (Random.Range(-2, 2), -6, 0);
bBelow = false;
}//end if
}
}