public class ProjectileFlightTimeUntilDecay : MonoBehaviour
{
public float PlayerProjectile;
public float timeUntilDecay = 5.0f;
void Start()
{
timeUntilDecay = timeUntilDecay * Time.deltaTime;
}
// Update is called once per frame
void Update()
{
if(timeUntilDecay <= 0)
{
// Destroy the projectile
}
}
}
I tried this, and doesn't work.
CodePudding user response:
timeUntilDecay
is never decreased from its initial value, so the check if (timeUntilDecay <= 0)
will never be true.
Typically this is done by decrementing it in Update()
, e.g.
timeUntilDecay -= Time.deltaTime;