It was fun and I got it working +added some camera follow and level changing already, but I can’t find out how to deal with all the birds sitting around level
I thought that it would be good to script some check if the bird is still moving and destroy the bird when it has stopped, but I can’t just figure out how to do it and I’ve tried googling around for days to get hints without success.
This most likely is very easy to do, but unfortunately I just can’t figure it out.
If the birds are (I suspect) Rigidbody or Rigidbody2D’s you could check its rigidbody.velocity’s magnitude to see if it is moving… if the value is below some small number or zero, your object doesn’t move and you can remove it or set it kinematic or whatever.
Thank you for the advice. Could you help a noob a little further?
I have this bird prefab
that is the one slingshot to field. It has two scripts attached and one of those (Pull And Release) destroys itself after mouse/finder is detached to slingshot the bird, so this other one could possibly be used to destroy the bird from scene after it has stopped moving, or close to it.
I just don’t know how to code it?
Code is below:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Trail : MonoBehaviour
{
//Trail Prefabs
public GameObject[ ] trails;
int next = 0;
// Start is called before the first frame update
void Start()
{
// Spawn a new Trail every 100 ms
InvokeRepeating(“spawnTrail”, 0.1f, 0.1f);
}
void spawnTrail()
{
// Spawn Trail if moving fast enough
if (GetComponent().velocity.sqrMagnitude > 25)
{
Instantiate(trails[next], transform.position, Quaternion.identity);
next = (next + 1) % trails.Length;
}
}
}
I tried to modify that with the attached screenshot, but I get the error.