Hey guys, I’m making a prototype game for one of my uni module’s. Its a simple game where the player has to try and catch the spawning object. I’ve got the score to increment by 1 but how do I go about taking the score away if the player misses the object.
code
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour
{
public GUIText SugarProductionText;
private int SugarProduction;
// Use this for initialization
void Start ()
{
SugarProduction = 0;
SetSugarProductionText();
}
// Update is called once per frame
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Sugar")
{
other.gameObject.SetActive(false);
SugarProduction = SugarProduction + 3;
SetSugarProductionText();
}
else if(other.gameObject.tag == "Terrain")
{
other.gameObject.SetActive(true);
SugarProduction = SugarProduction - 1;
SetSugarProductionText();
}
}
void SetSugarProductionText()
{
SugarProductionText.text = "SugarProduction" + SugarProduction.ToString();
}
}
I tried applying a tag to the terrain, so if the object spawning touches the terrain the player score would go down, but it doesn’t.