Search Unity

Bug Animation in my Flappy Bird clone won't work.

Discussion in 'Animation' started by shurikenplayz123, Mar 2, 2023.

  1. shurikenplayz123

    shurikenplayz123

    Joined:
    Oct 24, 2020
    Posts:
    6
    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.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class pipeOpener : MonoBehaviour
    6. {
    7.     public Animator Anim;
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.    
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update()
    16.     {
    17.  
    18.     }
    19.     private void OnTriggerEnter2D(Collider2D collision)
    20.     {
    21.         if (collision.gameObject.CompareTag("Open"))
    22.         {
    23.             Debug.Log("played");
    24.             Anim.Play("pipeOpen");
    25.         }
    26.     }
    27. }
    28. Pls help.
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    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.
     
    Last edited: Mar 3, 2023
  3. shurikenplayz123

    shurikenplayz123

    Joined:
    Oct 24, 2020
    Posts:
    6
    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.
     
  4. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    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.
     
  5. shurikenplayz123

    shurikenplayz123

    Joined:
    Oct 24, 2020
    Posts:
    6
    I FINALLY F***ING FIXED IT BBY
     
  6. shurikenplayz123

    shurikenplayz123

    Joined:
    Oct 24, 2020
    Posts:
    6
    Thanks for helping:)
     
    Unrighteouss likes this.