Hi!
New to Unity and C#, so apologies if this is obvious, but I have done a lot of searching and haven’t found a solution to this yet…
I have a 2D player object (set up with a box collider 2D and as a rigidbody2D). I want to interact with other objects in the scene to provide clues. First clue object - set up with box collider 2D with ‘is trigger’ checked. Player interacted as required.
Second clue object - identical set up and script (different sprite and tag). Player is interacting as though the object is a standard box collider without ‘is trigger’ checked.
I have:
- Double checked ‘is trigger’ is checked.
- Reset the box collider and tried again
- Changed the tag to match that of the first clue object so the event should be triggered by the script associated with the first object tag (to check I haven’t accidentally mistyped etc)
- Removed all surrounding boxcolliders (walls etc) to check player isn’t being blocked
Player is still stopping when she collides with the object rather than triggering the scripted event. (Which still triggers fine for the first game object).
I’m pretty sure its going to prove to be something innocuous and simple but I’m fresh out of ideas - any help would be appreciated! I don’t think it’s the script (as it works fine with the first game object) but I’ve copied the relevant lines below just in case.
Thanks!
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag ("FullBed"))
{
other.gameObject.SetActive(false);
bedImage.SetActive(true);
}
else if (other.gameObject.CompareTag ("ExitM1toM2"))
{
other.gameObject.SetActive(false);
aftExitImage.SetActive(true);
}
}
}