Like i have item,which called Coin
For coin i want to add to my score +1
Than i have another item which called Golden coin, and for it i want to add to my score +2
I need to create script with virtual method and overriding.
This is my script but the second part doesnt work tho
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Coin : MonoBehaviour
{
protected int Score = 0;
public Text Text;
public virtual void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Coin")
{
Score++;
Destroy(other.gameObject);
Text.text = Score.ToString();
}
}
}
public class GoldenCoin : Coin
{
public override void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "GoldenCoin")
{
Score = Score + 2;
base.OnTriggerEnter(other);
}
}
}