Issue with my Teleport Script

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){
		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.

On line 20, if you want to destroy the player, it would be


This is a function scope issue. The variable “other” doesn’t exist in the function. The method OnMouseDown() is not your own method. You are overriding the method from a base class, so you can’t just change what gets passed to it. When you change the function parameters, it becomes a different, unique, function. I would recommend brushing up on some programming basics online that will cover these. I like myself, great videos there. Good luck.