Skip to content

Instantly share code, notes, and snippets.

@listopad
Created April 23, 2018 21:13
Show Gist options
  • Save listopad/cf710bd6a847bebe2860631c27413398 to your computer and use it in GitHub Desktop.
Save listopad/cf710bd6a847bebe2860631c27413398 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
public class Collector : MonoBehaviour
{
private int score;
public int goal;
public string objectTag;
public Text textWindow;
public UnityEvent GoalAchieved;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag(objectTag))
{
score++;
textWindow.text = score.ToString();
other.gameObject.SetActive(false);
if (score == goal) GoalAchieved.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment