- Home /
my OnTriggerEnter function won't get called
So I am trying to implement a teleporter script for my game. I'm pretty sure this should work but for some reason my game won't call the OnTriggerEnter function. I have rigid body turned on and box collider 2d with the is trigger on.
My player should be colliding with the particle object and transport it self to another particle object.
Here's my code so far, is there something I should change in the C# script?
using UnityEngine;
using System.Collections;
public class TeleportController : MonoBehaviour {
public GameObject destination;
public float adjust;
public bool jump;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider other)
{
Debug.Log("About to teleport!");
if(!jump)
{
Debug.Log("Teleporting!");
if(other.tag == "Player")
{
destination.GetComponent<TeleportController>().jump = true;
other.transform.position = new Vector3(destination.transform.position.x, destination.transform.position.y + adjust, 0f);
}
}
}
void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
jump = false;
}
}
}
Answer by graciasluigi · Sep 22, 2015 at 12:06 PM
MonoBehaviour.OnTriggerEnter2D(Collider2D)
instead of
MonoBehaviour.OnTriggerEnter2D(Collider)
http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html
I am not sure if this is the problem.
OH! Thanks, yeah that fixed my issue, I didn't even noticed that.
Your answer
Follow this Question
Related Questions
Car made of boxes teleports on hard collision 0 Answers
Trigger Spawning? 1 Answer
OnTriggerEnter and GUIText problem 0 Answers
Destroy object 1 if player walks into object 2 1 Answer
Colliding two GameObjects 1 Answer