Animation in my Flappy Bird clone won't work.

I made a Flappy Bird clone recently following a tutorial by GMTK. I added a gun to the game that is supposed to open the pipes when the bullet hits a target. The pipe animation plays when they are made and I don’t know how to fix it. There is also a error that says my collider failed verification. I made a video explaining my problem.

Here is my code to open the pipes.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class pipeOpener : MonoBehaviour
{
    public Animator Anim;
    // Start is called before the first frame update
    void Start()
    {
    
    }

    // Update is called once per frame
    void Update()
    {

    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Open"))
        {
            Debug.Log("played");
            Anim.Play("pipeOpen");
        }
    }
}
Pls help.

You’ve already found the issue; the animation is playing early.

The reason it’s playing early is because it’s the “Start” state in the animator. It’s the animation that… starts. To fix this, create an empty state, right click and make it the “Start” state. I’m pretty sure that alone will fix the issue.

Thank you for the comment. I actually fixed my problem but now when I spawn in my bullet prefab the animator reference attached to it changes when I spawn it in.

  1. Why does your bullet have an animator reference? (asking because I don’t see any animation in your video)
  2. What do you mean by “changes” - does it switch to a different animator, or come up empty?
  3. What did you change to fix your issue? Something must be causing the new issue.

One thing to check is that whatever animation is playing on the bullet isn’t also setting a new animator. You can look through the properties for that animation and see what’s being modified.

I FINALLY FUCKING FIXED IT BBY

Thanks for helping:)

1 Like