- Home /
Question by
Delloy · Jul 23, 2020 at 05:09 PM ·
script.score systemcollectible-game-objects
Multiple score values
Hi,
I would like to have multiple objects with a variation of different "scores/points", for an example, one coin is worth 1 point and another is worth 20. How would I go about implementing this? This is the code I have so far;
public class CoinScript : MonoBehaviour
{
public GameHandler GH;
public AudioClip coinSound;
// Start is called before the first frame update
void Start()
{
GH = GameObject.Find("Canvas").GetComponent<GameHandler>();
}
private void OnTriggerEnter(Collider other)
{
GH.coins++;
AudioSource.PlayClipAtPoint(coinSound, transform.position);
Destroy(gameObject);
}
Second Script;
public class GameHandler : MonoBehaviour
{
public TextMeshProUGUI CoinText;
public int coins = 0;
private void Update()
{
CoinText.text = "Coins Collected : 0 " + coins;
}
}
Comment
Best Answer
Answer by pmurph03 · Jul 23, 2020 at 11:19 PM
On your conscript you could add a variable public int CoinValue = 20
And where you currently do GH.coins++
you could do GH.coins+= CoinValue
Your answer
Follow this Question
Related Questions
Adding value from a clone object to score 4 Answers
Scoring Points. 1 Answer
Multiple objects being destroyed, count for them being destroyed doesnt go up past once. 2 Answers
ScoreBoard Help 1 Answer