I am currently making a simple game for year 1 game design, and for some reason just can’t figure out how to make my 2D character teleport along the X axis when he enters and presses “e” a trigger. Even helping me get him to move only upon entering the trigger, and not having to press a button would be of great help. Here is my current void OnTriggerEnter2D(note: the top portion is obviously irrelevant to the translation):
void OnTriggerEnter2D(Collider2D col)
{
if (col.CompareTag("Coins"))
{
Destroy(col.gameObject);
gm.points += 1;
}
if(col.CompareTag("Door") && Input.GetKeyDown("e"))
{
transform.position = new Vector2(transform.position.x + speed, 0);
print("door working");
}
}
I also have this way above the prior bit of code:
public float speed = 50f;