Hello .
I have a question guys . I got a score script written in C# and the Class is " Score " .
And i have game object that i want to destroy it if the Score = 1000 .
How can i do that please ?
public Score Point;
public int score;
// Use this for initialization
void Start () {
if( Point= 10){
Destroy(gameObject);
}
}
This is pure EXAMPLE, should get you where you need to be. Say you have a GameObject called “Scripts” in your scene’s Hierarchy. This GO has a script attached, called “Score”. Let’s say this is “Score”.
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour
{
[HideInInspector]
public int score = 0;
void Update()
{
//TEST
if(Input.GetKey(KeyCode.Return))
score+=10;
}
void OnGUI()
{
GUILayout.Label ("Score - " + score.ToString ());
}
}
Then, say you have a GO with a script attached called “DestroyOnWin”, and this is “DestroyOnWin” class:
using UnityEngine;
using System.Collections;
public class DestroyOnWin : MonoBehaviour
{
public Score scoreScript;
void Start()
{
//Find Scripts GameObject, and get Score Component.
scoreScript = GameObject.Find ("Scripts").GetComponent<Score>();
}
void Update()
{
if(scoreScript != null && scoreScript.score >= 1000)
Destroy (gameObject);
}
}