I have two separate ladders and Ant Hills. When I debug it says the object name is the name of the first object it interacted with not the second one. For example: Ladder 1 take you to Ant Hill 1 and Ladder 2 is suppose to take you to Ant Hill 2 and vice versa. But when I debug it says the object is Ant Hill 1 and Ladder 1 even if I’m on Ant Hill 2 or Ladder 2. Here is my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Teleporter : MonoBehaviour
{
GameObject Player;
bool Touching;
void OnTriggerEnter2D(Collider2D obj)
{
if (obj.tag == "Player")
{
Touching = true;
Player = obj.gameObject;
}
}
private void Update()
{
if(this.tag == "Ant Hill")
{
if (Touching && Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
{
switch (this.name)
{
case "Ant_Hill_1":
Player.transform.position = new Vector3(8.91f, -13.53f, 0);
break;
case "Ant_Hill_2":
Player.transform.position = new Vector3(84.91f, -13.53f, 0);
break;
default:
break;
}
}
}
else if(this.tag == "Ladder")
{
if (Touching && Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
{
switch (this.name)
{
case "Ladder_1":
Player.transform.position = new Vector3(8.91f, -2.152604f, 0);
break;
case "Ladder_2":
Player.transform.position = new Vector3(84.91f, -2.152604f, 0);
break;
default:
break;
}
}
}
}
private void OnTriggerExit2D(Collider2D obj)
{
if (obj.tag == "Player")
{
Touching = false;
}
}
}