Hi, I wrote code to make the wings on my bird flap each time the player presses a space bar. This seems to work fine in the editor but after I build the game, they freeze in the final product. I’m aware my code is far from stellar since I’ve only just begun, but I’d appreciate any help. Thanks!
Streamable link to video: Watch 2024-07-29 20-37-08 - Trim | Streamable
Script for my wings:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WingAnimation : MonoBehaviour
{
public BirdScript bird;
private int flapTimer;
private int flapCoolDown = 200;
private bool flapCooled = false;
private bool justFlapped = false;
// Start is called before the first frame update
void Start()
{
bird = GameObject.FindGameObjectWithTag("Bird").GetComponent<BirdScript>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && bird.birdIsAlive)
{
if (flapCooled == false)
{
transform.Rotate(-180, 0, 0);
flapCooled = true;
flapTimer = flapCoolDown;
justFlapped = true;
//Debug.Log("First flap");
}
else
{
flapTimer = flapCoolDown;
}
}
if (flapTimer == 0 && justFlapped)
{
transform.Rotate(-180, 0, 0);
flapCooled = false;
justFlapped = false;
//Debug.Log("Second flap");
}
if (flapTimer != 0)
{
flapTimer -= 1;
}
}
}