public class birdScript : MonoBehaviour
{
private GameObject bird;
// Update is called once per frame
void Update()
{
if(gameObject.transform.position.y < -20)
{
Destroy(gameObject);
}
}
public void hitCheck(float playerx, float playery)
{
if(playerx - 2 < gameObject.transform.position.x && playerx + 2 > gameObject.transform.position.x)
{
if (playery - 2 < gameObject.transform.position.y && playery + 2 > gameObject.transform.position.y)
{
DestroyBird();
}
}
}
void DestroyBird()
{
Debug.Log("die");
bird = gameObject;
Destroy(bird);
}
}
So basically I have a birdPrefab and on that prefab I have a bird script. In the script I want to destroy the bird if hitcheck is called, but it says that it is not permitted. I have tried to look for this in other places but none of them had answers specific for destroying the gameObject.