Question by
matt_sunley · Aug 29, 2015 at 03:24 AM ·
collisionscript.scorescore systemcounter
How do you add +1 to a score counter after a destroy script (C#)?
I need a script that adds 1 to my score when a destroy script is triggered. This is my destory script. using UnityEngine; using System.Collections;
public class DestroyScript : MonoBehaviour
{
public GameObject Explosion;
void OnTriggerEnter (Collider Other)
{
if(Other.tag == "Player")
{
Instantiate (Explosion,transform.position, transform.rotation);
Destroy(gameObject);
}
}
} strong text
Comment
Answer by SpaceManDan · Aug 29, 2015 at 03:49 AM
public GameObject Explosion;
private float score;
void OnTriggerEnter (Collider Other)
{
if(Other.tag == "Player")
{
Instantiate (Explosion,transform.position, transform.rotation);
score++;
Destroy(gameObject);
}
}
Do you have a UI Text object already? Like, do you already have a working/existing UI or do you need to add one from scratch?
Your answer
Follow this Question
Related Questions
How can I keep a score counter of how many points the player has collected on the screen? 1 Answer
My character doesn't detect collisions or Hinge joint. 0 Answers
How do I add a score system? 1 Answer
Kill counter doesn't stop counting 0 Answers
Strange (Pun2) RPC Problem. (With Error message that doesn't appear in a google search at all) 1 Answer