My script is working just one time
I want to transport my "player" when I press E in a collider. Is everything fine. But I can only do it one time. If I try to do it again it doesnt works. The only part that is working is the UI that says: Press E to enter.
This is the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TPDoor : MonoBehaviour
{
public GameObject UIText;
public GameObject TPObject;
public Transform PositionToTP;
private void Start()
{
UIText.SetActive(false);
}
void OnTriggerStay(Collider other)
{
UIText.SetActive(true);
if (other.tag == "Player" && Input.GetKeyDown(KeyCode.E))
{
TPObject.transform.position = PositionToTP.transform.position;
}
}
private void OnTriggerExit(Collider other)
{
UIText.SetActive(false);
}
}
Answer by tormentoarmagedoom · Feb 20, 2020 at 02:16 PM
Hello..
I dont understand, in this part:
void OnTriggerStay(Collider other)
{
UIText.SetActive(true);
if (other.tag == "Player" && Input.GetKeyDown(KeyCode.E))
{
TPObject.transform.position = PositionToTP.transform.position;
}
}
If checking if the other is the payer, i understand the script is the "teleporter" script.
Then why you change the position of the teleporter? And not the position of the player?
TPObject.transform.position = PositionToTP.transform.position;
Your answer
![](https://koobas.hobune.stream/wayback/20220612223637im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having trouble moving a GameObject to another scene and Transform it to a different position 0 Answers
Enemy kill counter only counts first killed enemy 0 Answers
Does anyone know why transform.position isn't working? (See details) 1 Answer
The requested feature is not implemented. 0 Answers
Door open with Key script isn't working 0 Answers