i need my player in unity to teleport to a certain location when he touches a tagged object

1.6k views Asked by At

I need my player to teleport somewhere when he bumps into a (unity) gameobject with a certain tag (are you seen) on it. I already found a solution, but then I switched my player's movement to a character controller and now it doesn't work. This is my current script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class found: MonoBehaviour
{
      private void OnTriggerEnter(Collider collider)
      {
            if (collider.gameObject.tag == "are you seen")
            {
                transform.position = new Vector3(-15.38f, 1.93f, 62.1f);
            }
      }
}
1

There are 1 answers

2
ChilliPenguin On

When you switched to character controller, did you remove the rigidbody and collider? An OnTriggerEnter event still requires the player to have a collider with IsTrigger = true, and one of the gameobjects to have a rigidbody. Here is what the offical documentation says.

Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.