So I’m working on my first game using unity, it’s a simple floppy bird re-creation, I follower a video, but the video didn’t include how to animate your characters, thus I wanted to learn how to animate it myself
I just started to add an animation when the bird flies (after hitting the spacebar), and as I mentioned it would only be triggered after hitting the spacebar so I used a Boolean in the transition, and used the following script to connect the animation to the actual thing
this is the script I used
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
// inaisly the script is not aware of the things we added into the object
//we need to make those conctions using a refrance
public Rigidbody2D BirdRigidBody;
public float flapStentgh;
public LogicScript logic;
public bool AliveBird = true;
public Animator BirdAnimator;
//after making the varible go back to unity and drag the rigid body in
// Start is called before the first frame update
void Start()
{
logic = GameObject.FindGameObjectWithTag("logic").GetComponent<LogicScript>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)==true &&AliveBird) {
BirdRigidBody.velocity = Vector2.up * flapStentgh;
BirdAnimator.SetBool("flapping", true);
}
if (transform.position.y <-17)
{
logic.GameOver();
AliveBird=false;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
logic.GameOver();
AliveBird = false;
}
}
the comments are my notes during the tutorial so don’t pay so much attention to it
the problem that accrued is that now after I hit the spacebar the game pauses, it doesn’t crash, just poses , I tried to look into some keyboard shortcuts, but found nothing
and the once I removed the BirdAnimator.SetBool("flapping", true);
from my script it went back to functioning normally(without the animations of course), so I assume the problem is there
I hope they’re would be someone who can help me, or provide an explanation of why this is happening
Thank you very much!