When near object, able player to click it and then player teleports.

Hi everyone! Im making MMORPG game like runescape and im using portals to teleport from place to other. I need help with script and it would be something like..

var distance : float;

function update () {

if(Input.GetMouseButtonUp(0))
  //Here what distance it needs to be that player is able to teleport.
  //Here teleport player..

//Teleport distance is something like if(distance < 3.0); and then player is able to teleport.

But i tried to search about this and tried to make script myself.. But i cant make it like that! Debug Console gives me so much errors that sometimes my computer does "Dump Error"!

So, i ask you everyone.. Please make me script that teleports me when im near enough (3.0) and when i click teleport.

Thank you very much!

Lewenos

1 Answer

1
var distance;
var canTeleport = false;
var teleporter : Transform; // The teleporter goes here.

function Update ()
{
distance = Vector3.Distance(teleporter.position, transform.position)

if(distance < 3)
   {
   canTeleport = true;
   }
   else
   {     
   canTeleport = false;
   }
   if(canTeleport && Input.GetButtonDown("Fire1"))
   {
   //Change position here.     
   }
}

Now it should be fixed. If not please tell and I will actually grab it by the horns and test it.

If you can wait a few hours I will correct the mistakes. Right now I am at a birthday party and I only got my Android device with me, but I will correct the code when I get home :)

it soould be fixed now :D

You're answering questions from an mobile device at a birthday party? Quick! Someone gives this man the medal of valiance!

He, I have no idea what valiance means, but birthday partys are boring for a 15 year old like me, so I might aswell do something about it, right? :)

Oh, is that because you are using the "Move to click" script. And when you are near the teleporter you click to teleport and it will move to where you have clicked after the teleportation?