I’m trying to make a script that will allow me to click on a Collider (with mouse button) that will destroy my player and create it in another location. (using a prefab of the player)
The current script i have is based of 2 seperate scripts (that work fine). One is an push the button and the elevator goes up or down. The other is my Killzone for when players fall down the level and it will respawn them at the start of the level.
#pragma strict
private var pressedButton : boolean = false;
private var teleportup : boolean = false;
var Player : GameObject;
var location2 : Transform;
function OnTriggerEnter2D(other : Collider2D){
pressedButton = true;
}
function OnTriggerExit2D(other : Collider2D){
pressedButton = false;
}
function OnMouseDown(){
if(teleportup == true){
Destroy(other.gameObject);
var P : GameObject = Instantiate(Player, location2.position, Quaternion.identity);
}
}
function OnGUI()
{
if(pressedButton == true){
GUI.Box(new Rect(300,300,200,20), "Click to Activate!");
}
}
The error i’m currently getting is:
teleporter.js(20,25): BCE0005: Unknown identifier: ‘other’.
I’ve tried adding function OnMouseDown(other : Collider2D), trying to identify the “other” but that doesn’t seem to work. It allows me to go ingame with that though, but when i click on the collider i get the following error:
Failed to call function OnMouseDown of class click teleporter
Calling function OnMouseDown with no parameters but the function requires 1.
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)
My knowledge of programming is limited and i have alot of learning ahead of me, so any help would be appriciated.