I recently got into unity and I am at a stan still because I want to stop the pipes from moving after the bird has died to prevent the score from going up after losing. I’m really confused on what I should I have posted the code to the BirdScript
and the PipeScript
.
BirdScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public float flapStrenth;
public LogicManager logic;
public bool birdIsAlive = true;
// Start is called before the first frame update
void Start()
{
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicManager>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && birdIsAlive )
{
myRigidbody.velocity = Vector2.up * flapStrenth;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
logic.gameOver();
birdIsAlive = false;
}
}
PipeScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PipeScript : MonoBehaviour
{
public float moveSpeed;
public float deadZone = -15;
public BirdScript birdScript;
void Update()
{
transform.position = transform.position + (Vector3.left * moveSpeed) * Time.deltaTime;
if (transform.position.x < deadZone)
{
Debug.Log("Pipe Deleated");
Destroy(gameObject);
}
}
}