I'm trying to make it so that it will increase score by 10 when the gem is picked up by the Player gameObject.
I have the Count: text on screen, but it isnt increasing by 1 when the prefab is picked up.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class RandomSpawn : MonoBehaviour {
public GameObject Gem;
private int count;
public Text countText;
void Start()
{
count = 0;
SetCountText ();
}
void SpawnGem()
{
Vector3 RandomSpawn = new Vector3 (Random.Range (-8.87F, 8.87F), Random.Range (-3.87F, 3.97F),1F);
Instantiate (Gem, RandomSpawn, Quaternion.identity);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag ("Player"))
{
count = count + 10;
SetCountText ();
SpawnGem ();
Destroy (Gem);
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
}
}
Many thanks
↧