- Home /
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
Answer by FLASHDENMARK · Apr 24, 2011 at 06:35 PM
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.
I just added some variables.. :)
Like: var destination : Transform; var Player : Transform;
And then:
if(distance < 3 && Input.GetButtonDown("Fire1")) { Player.transform.position = destination.position; } }
And, some things needs fixing.. Like i can teleport anywhere.. Always when i click "fire1", i got teleported. And then it needs to be something like when i click THAT OBJECT, i will teleport.
Thanks, i will wait for answer. :)
I hope you can help me.
Lewenos
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 :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613124959im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Z Vector Teleportation Help 0 Answers
Click to move script, need help. 1 Answer
OnMouseEnter Error 1 Answer