I just started using the 2D tools in Unity but this behavior seems a little odd: I have two sprites with (for testing purposes) each a Box Collider 2D on them, both set to isTrigger.
One has a script attached to control it and register collisions, but the method never gets called even though they should collide! Also if this for some (obvious) reason can’t work, what would be a work around without using Rigidbody2D?
PlayerController.cs:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
void Start () {
}
public void Update()
{
float horizontal = Input.GetAxis("Horizontal") * 0.1f;
float vertical = Input.GetAxis("Vertical") * 0.1f;
transform.Translate (horizontal, vertical, 0);
}
void OnTriggerEnter2D(Collider2D other) {
Debug.Log ("was hit");
}
}
EDIT
Noticed the thing about triggers and reverted to normal BoxColliders. Both Objects are on the same z-value. To clear things up:
PlayerObject:
- SpriteRenderer
- PlayerControllerScript (see below)
- BoxCollider2D
OtherObject:
-
SpriteRenderer
-
BoxCollider2D
void OnCollisionEnter2D(Collision2D coll) {
Debug.Log (“was hit”);
}