(C#) OnTriggerEnter2D wont trigger.
I'm trying to make a coin, if you pass over it plays an animation 'Pickup' I tried debuging and it wont trigger even if I pass into it.
using UnityEngine;
using System.Collections;
public class coinAnimation : MonoBehaviour {
Animator animator;
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("Collided!")
if (collision.gameObject.tag == "ball")
{
animator.SetTrigger("Pickup");
}
}
// Use this for initialization
void Start()
{
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
}
}
Here is some screen caps: 
Answer by 5c4r3cr0w · Aug 11, 2016 at 04:53 AM
You're using wrong function. If you want it to respond it with Trigger then you need to use function
OnTriggerEnter2D()
Ref : https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html
Or you can make it work if you just uncheck "Is Trigger" (Assuming other object has rigidbody2d attached to it)
Also you haven't created transiction in your animator controller that can play "Pick Up" animation when Trigger "Pickup" is set.
Your answer
Follow this Question
Related Questions
Leaping Enemy - How to? 0 Answers
SOS: Errors on play despite successful build 0 Answers
Unity 5 Animator Window doesn't open 0 Answers
2D Dynamic Lights and Shadows 0 Answers
2D anims with same animation but with different sprites. Character creation. 0 Answers