I have this script that is currently working fine, and I want to add some extra code so that if I hit an object with a different tag it subtracts 300 points. In other words, here is the script that works well:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class POINTS : MonoBehaviour
{
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 300;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Score: " + count.ToString();
if (count >= 10000)
{
winText.text = "Congrats! To play again press <";
}
}
}
And I think that this should work (note that I added some code after count = count + 300 so that in theory it should start subtracting points
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class POINTS : MonoBehaviour
{
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 300;
if (other.gameObject.CompareTag("TestSolid"))
{
other.gameObject.SetActive(false);
count = count - 300;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Score: " + count.ToString();
if (count >= 10000)
{
winText.text = "Congrats! To play again press <";
}
}
}
But if I try to run that it says that SetCountText hasn't been declared. How do I get this to work? I am very new to scripting so sorry if this is a stupid question. Thank you!
Closing bracket is missing. I think you should learn how to read compiler output.