- Home /
Manipulating Variables Over Multiple Scripts
I have a variable that I want to change from another sript, I am using the following script named 'Key' but it doesn't seem to change 'MaxObjectCount'
var enemyPrefab : GameObject;
static var MaxObjectCount = 0;
function checkhit(){
if(MaxObjectCount == 2){
Debug.Log("Two enemy: destroy");
Destroy(GameObject.Tag("Enemy"));
MaxObjectCount -=1;
}
if(MaxObjectCount == 1){
Debug.Log("One enemy");
}
}
In another script I have this Key.MaxObjectCount += 1;
But it is not changing 'MaxObjectCount' at all
I basically want 'MaxObjectCount' to rise by one whenever I use a function in another script.
Any ideas?
Looks right to me. Are you sure the other script is actually calling it and that something else isn't automatically decrementing it (like the checkHit function?)
Ok, I dont think so, just for safe measure, here is the other script that I am changing the variable from:
var destroySpawn : GameObject[]; destroySpawn = GameObject.FindGameObjectsWithTag ("Spawner");
var prefab : Transform;
function OnTriggerEnter( hit : Collider){
if (hit.gameObject.tag == "Player"){
Instantiate(prefab, transform.position + transform.forward*5, transform.rotation);
$$anonymous$$ey.$$anonymous$$axObjectCount += 1;
//Instantiate (prefab);
Debug.Log("Spawning Enemy");
//if (hit.gameObject.tag == "Player"){
//Destroy(gameObject);
for (var Spawner in destroySpawn) {
Destroy(Spawner);
}
}
}
Your answer
Follow this Question
Related Questions
Non-Static Accessibility 1 Answer
Accessing Other Scripts Without Using Static Variables 1 Answer
Static variables 1 Answer