Hello,
I wanted to make a script that would change a static variable that’s attached to several objects that change their render toggle. The game has an isometric view, and rooms will become visible when tripping over one of a few room triggers that will change the camera’s position, and render the room the player is currently in. The triggers would have their own value and would then change the one static variable. So I can change the trigger variable for each trigger object.
The problem I’m facing is that when hitting the trigger, the variable automatically sets itself to 0. If I take out the trigger variable and just place in [cameraIsometric.roomNumber = 1], the number changes appropriately. So the variable does not change. What would be the best option to change the variable?
Heres what I got down:
(triggerExperiment) [Trigger code]
var setMyNumber:int;
var target: Transform;
function Start () {
if (target == null && GameObject.FindWithTag("Player"))
target = GameObject.FindWithTag("Player").transform;
}
function Update()
{
}
function OnTriggerStay() {
if(target.gameObject.tag == "Player"){
collider.isTrigger = true;
print("Collision On");
cameraIsometric.roomNumber = setMyNumber;
print(setMyNumber);
//print(cameraIsometric.roomNumber);
}
}
function OnTriggerExit() {
if(target.gameObject.tag == "Player"){
collider.isTrigger = true;
print("Collision Off");
}
}
(cameraIsometric) [Changes render/camera position]
static var roomNumber : int = 0;
function Awake () {
//roomNumber = 0;
}
function Update()
{
if(roomNumber == 0)
{
transform.position = Vector3(-9,13,-43);
}
if(roomNumber == 1)
{
transform.position = Vector3(9,12,24);
}
if(roomNumber == 2)
{
transform.position = Vector3(-87,28,3);
}
}