My sceneManagers score doesn’t get updated until after I stop playing. It’s not so much that I can’t find a way to get the result I wan’t as I probably could using static variables, it’s more about learning why it doesn’t get updated in game and how to achieve this using GetComponent. The OnTriggerEnter is detected and everything, the only problem I have is that the score doesn"t get updated while the game is running. When I stop the game and hit play again suddenly the score is no longer 0 and it reflects how many points I scored in my last playthrough, and it’ll keep adding like this on and on. I can simply make score = 0 at start, that’s an easy fix, but I just typed this to show that the points are getting scored.
This is on my players script
function OnTriggerEnter2D(other : Collider2D)
{
if(other.tag == "Score")
{
sceneManager.GetComponent(SceneManagerScriptX).score += 1;
}
This is my sceneManagers script
#pragma strict
var alive : boolean = true;
var score : int = 0;
function OnGUI()
{
GUI.Label(Rect(100,100,100,100), "score" + score);
}
Update: Cleaned the code up a bit.