Write, so, after learning some basic C# i've gone on to follow a tutorial to get the VERY basics down of Unity.
I'm trying to use the boolean birdIsAlive from BirdScript.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myRigidBody;
public float flapStrength;
public LogicScript logic;
public bool birdIsAlive;
// Start is called before the first frame update
void Start()
{
birdIsAlive = true;
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && birdIsAlive == true)
{
myRigidBody.velocity = Vector2.up * flapStrength;
}
if (transform.position.y < -12 || transform.position.y > 1088)
{
logic.gameOver();
birdIsAlive = false;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
logic.gameOver();
birdIsAlive = false;
}
}
I'm trying to use it here (line 25 is where the issue is)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
public class PipeMiddleScript : MonoBehaviour
{
public LogicScript logic;
public BirdScript bird;
// Start is called before the first frame update
void Start()
{
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.layer == 3 && bird.birdIsAlive == true)
{
logic.addScore(1);
}
}
}
Any help would be much appreciated!
I thought that referencing the BirdScript at the top would allow me to use the boolean to check if the bird is alive before adding score for crossing a trigger.