Hello everybody,
after the writing of this code, that is supposed to be a two-way teleporter (you can teleport to another teleporter and SHOULD teleport back), ive run into a problem. It only teleports one way. The teleporter teleports to the other one, but then once you activate it again it teleports to the same teleporter, so you just teleport to the teleporter you are at. Does anybody know how to fix this?
EDITED FOR NEW CODE:
using UnityEngine;
using System.Collections;
public class PlayerTeleporter : MonoBehaviour {
public Transform playerTransform;
public Transform curTeleportTransform;
public Transform targetTeleportTransform;
public float curDistance;
public float useRange;
void FixedUpdate () {
playerTransform = GameObject.Find("player").transform;
curTeleportTransform = transform;
curDistance = Vector3.Distance(curTeleportTransform.position, playerTransform.position);
if (Input.GetButtonDown("Use teleporter") && curDistance < useRange)
{
playerTransform.position = targetTeleportTransform.position;
Debug.Log(targetTeleportTransform.position);
}
}
}
↧