- Home /
Question by
bigmike777 · Jul 26, 2020 at 10:21 AM ·
c#3dfps
how to make it so that when I get all the targets with the target code a win screen pops up
how to make it so that when I get all 21 targets with the target code a win screen pops up. this is target code.
using UnityEngine;
public class Target : MonoBehaviour
{
public float health = 100f;
public void TakeDamage (float amount)
{
health -= amount;
if (health <= 0f)
{
Hurt();
}
}
void Hurt ()
{
Destroy(gameObject);
}
}
Comment
Answer by $$anonymous$$ · Jul 26, 2020 at 11:28 AM
inside
private void Hurt ()
{
CheckTargets();
Destroy(gameObject);
}
private void CheckTargets ()
{
Target [] tata = FindObjectsOfType<Target>(); // finds all the target scripts
Debug.Log("Targets Left = " + tata.Length - 1);
if (tata.length == 1) // checks how many targets are left
{
// this was the only one left which will be destroyed after Void CheckTargets() is completed
// meaning now pop up the win ui
}
}
@nanavatidhruvik how would i edit the code for 21 targets
Your answer
Follow this Question
Related Questions
Trace 3D Basketball Shot 1 Answer
how to resize a decal 0 Answers
Fps Movement Velocity Decrease 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers