Help. I am a begginer and working on a simple 2D game, and this simple code won’t work
using UnityEngine;
using System.Collections;
public class DES : MonoBehaviour {
void OnTriggerEnter(Collider other)
{
Debug.Log(“enter”);
}
}
Both objects that I am trying to collide both have Rigidbody, and they both have colliders, the is trigger is checked on the object to which this script is attached.
I am coding in C#.
deathmask:
Help. I am a begginer and working on a simple 2D game, and this simple code won’t work
using UnityEngine;
using System.Collections;
public class DES : MonoBehaviour {
void OnTriggerEnter()
{
Debug.Log(“enter”);
}
}
Both objects that I am trying to collide both have Rigidbody, and they both have colliders, the is trigger is checked on the object to which this script is attached.
I am coding in C#.
You forgot to specify the parameter for OnTriggerEnter, it should be void OnTriggerEnter(Collider other), see http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html for more information.
1 Like
Thank you for pointing this out, but that doesn’t seem to be the problem i changed it in my question thank you
Can you post screenshots of your game objects showing the script and rigidbodies?
Here they are, thank you again
http://prnt.sc/b4av96
http://prnt.sc/b4avpa
The current state of the game is bad but it will be better once i figure out what the trigger problems are
tnx
Sorry, I’m not used to 2D on unity so I didn’t realize there were different methods for colliders here, try changing your OnTriggerEnter to this:
void OnTriggerEnter2D(Collider2D other)
1 Like
I solved it, Since
EnricoBC:
Sorry, I’m not used to 2D on unity so I didn’t realize there were different methods for colliders here, try changing your OnTriggerEnter to this:
void OnTriggerEnter2D(Collider2D other)
THANK YOU
That’s the problem it works now!
1 Like