Hi, I am facing a similar problem,
Here are my scripts
“script_Bullet.js” inside a gameObject “prefab_Bullet”
#pragma strict
var bulletSpeed:float = 50;
var refToSceneManager:script_SceneManager; // set a reference to script_SceneManager
function Update ()
{
transform.Translate(Vector3.up* Time.deltaTime* bulletSpeed);
}
function OnTriggerEnter(other:Collider)
{
if(other.gameObject.tag == "Asteroid")
{
refToSceneManager.addScore();
}
}
“script_SceneManager.js” inside gameObject “prefab_SceneManager”
#pragma strict
var canInstatiateAsteroid:boolean = true;
var minTime :float = 3;
var maxTime :float = 6;
var refToAsteroid :Transform;
var score :int = 0;
var gameTime :float = 60.0; // countdown timer to game ending
function Awake()
{
score = 0;
}
function Update ()
{
if(canInstatiateAsteroid == true)
{
instantiateAsteroid();
canInstatiateAsteroid = false;
}
}
function instantiateAsteroid()
{
GameObject.Instantiate(refToAsteroid,Vector3(0,-9,0),transform.rotation);
yield WaitForSeconds(Random.Range(minTime,maxTime));
canInstatiateAsteroid = true;
}
function addScore()
{
score++;
}
What I’ve realized is that at start of the scene, the score inside my SceneManager instance gets reset to zero, but the score inside my SceneManager prefab retain the value from previous run.
And when I start the scene again, score will be assigned the value of the prefab version ( which is whatever value retained from previous run) and not the instance version ( which has been reset to zero).
Why is the prefab score being changed? Shouldn’t it be just the instance that is affected?
Why is the prefab score being used? Not the instance score?
Would be grateful if anyone can shed some light on this. 