Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

My teleport JS script wont work properly...help?

Discussion in 'Scripting' started by thegamerguynz, Apr 15, 2016.

  1. thegamerguynz

    thegamerguynz

    Joined:
    Apr 1, 2016
    Posts:
    20
    hi guys and girls I've been trying to get it so that when you walk up to the door, a message displays, your press F and teleport out to the terrain. ive got the teleport mechanics working fine but as it sits at the moment the message permanently displays and pressing F teleports you even outside the collider.

    here is my script:


    var target : Transform;
    var player;
    var col;
    var message : String = "Press F to exit Ship";
    var displayMessage : boolean = false;
    var teleport : boolean = false;


    function Update () {
    player = GameObject.FindWithTag("Player");
    col = GameObject.FindWithTag("Teleport");

    if (teleport == true && Input.GetKeyDown(KeyCode.F)){
    player.transform.position = target.position;
    }
    }


    function OnTriggerEnter (col : Collider) {
    teleport = true;
    displayMessage = true; }

    function onTriggerExit (col : Collider) {
    displayMessage = false;
    teleport = false;
    }
    function OnGUI ( ) {

    if (displayMessage){
    GUI.Label(new Rect(Screen.width / 2, Screen.height / 2, 200f, 200f), message);
    }
    }
    any help is most appreciated!!
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Use code tags.
    I haven't tested the code but
    Code (CSharp):
    1. onTriggerExit
    should be
    Code (CSharp):
    1. OnTriggerExit
    otherwise Unity won't recognize the method.
     
  3. thegamerguynz

    thegamerguynz

    Joined:
    Apr 1, 2016
    Posts:
    20

    thanks for that !! :)