Hi I have a game were you walk up to a car and a GUI option pops asking you to press c to enter the car. Could you tell me what is wrong with my code please!
#pragma strict
var levelToLoad : String;
function OnCollisionEnter(col : Collision)
{
if (col.gameObject.name == "LANCEREVOX")
{
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Drive to City");
if (Input.GetKeyDown("c")) {
Application.LoadLevel(levelToLoad);
}
}
}
var levelToLoad : String;
private var enter : boolean;
//Main function
function Update ()
{
if(Input.GetKeyDown("c") && enter){
Application.LoadLevel(levelToLoad);
}
}
function OnGUI(){
if(enter){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'c' to open the door");
}
}
//Activate the Main function when player is near the door
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
enter = true;
}
}
//Deactivate the Main function when player is go away from door
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
enter = false;
}
}
I know its daft but i had some old code i forgot about, so i modified it and tested it out and it works so thanks any way for trying