- Home /
Teleporting Script Doesn't Work With Anything But The Player
Hey everyone! I have made a teleporting script and it works perfectly with the player. So when the player collides with the object tagged "teleportPad" it teleports to a game object specified. No problems there. I don't want the player to teleport though, I want an enemy mesh to teleport when it collides with the player mesh but it won't work. There aren't any reported errors too. Here's my code:
using UnityEngine;
using System.Collections;
public class Teleport : MonoBehaviour {
public Transform destination;
void OnControllerColliderHit(ControllerColliderHit col) {
if(col.collider.gameObject.tag == "teleportPad"){
transform.position = destination.position;
}
}
}
So basically how do I make this code work when the player collides with the enemy and then the enemy teleports. Thanks!
Answer by ZachVille · Jan 05, 2019 at 02:01 AM
The only change that you should need to make to your code is to change the tag on line 10 to whatever your player is tagged with. You also should put this script on your enemy gameObject.