Hey guys,
I am trying to create a simple game where when you die it tells you when you die. The variable, called surviedTime, is stored in a class called moveBullet. I am trying to reference it in a class called gameovermenu. It grabs the variable from the moveBullet class and prints it out on the screen. Here is the code:
moveBullet:
#pragma strict
var bullet: GameObject;
var force = 0.3;
var reloadTime = 0.05;
var lastShotTime = 0;
var isDead: boolean;
var timeTillSwitch = 3.0;
var fixedTime = 0.0;
var startTime: float;
var endTime: float;
var survivedTime: float;
function Start() {
startTime = Time.fixedTime;
}
function Update() {
this.transform.Translate(Vector3.forward * force);
var target = GameObject.Find("Rocket 1");
if(Vector3.Distance(target.transform.position, this.transform.position) < 2) {
Destroy(target.gameObject);
Destroy(this);
isDead = true;
endTime = Time.fixedTime;
survivedTime = endTime - startTime;
if(isDead == true) {
Application.LoadLevel("gameoverreplay");
}
}
}
gameovermenu:
#pragma strict
var survivedTime: float;
function Start () {
survivedTime = moveBullet.survivedTime;
}
function Update () {
}
function OnGUI() {
GUI.Box(Rect(580, 250, 150, 100), "You Died! Play Again?");
GUI.Box(Rect(580, 275, 150, 100), "You survived " + survivedTime + "seconds.");
if(GUI.Button(Rect(580, 350, 150, 100), "Play Again")) {
Application.LoadLevel("avoid");
}
}
After all this, it gives me the error:
An instance of type ‘moveBullet’ is required to access non static member ‘survivedTime’.
I kind of know what this means, but I don’t know how to fix it. Any help?
Thanks,
-Silent