I’m trying to combine make it such that when an object collides, the animation plays. I’m getting these 2 errors, but I have no idea why they’re errors?
here is my code
I’m trying to combine make it such that when an object collides, the animation plays. I’m getting these 2 errors, but I have no idea why they’re errors?
here is my code
I’m pretty sure you were trying to write this:
public class Collider : MonoBehaviour
{
public GameObject item;
public Animation anim;
private void Start()
{
anim = GetComponent<Animation>();
}
private void OnCollisionEnter(Collision col)
{
anim.Play();
}
}
Several things to note:
Start
method inside your OnCollisionEnter
method.foreach
statement must have a curley brackets scope after it, where you tell the program what to do in every iteration.Due to the above reasons, you faced these errors.
Good luck.