Ello!
Here i have a coin pinkup script that is not working. I am asking for help to give me a way on how i can fix this script.
The Money script is assigned to my Player character and i have the Coin script on the coins game object (The coin script does nothing, it’s simply used for the script as a sort of pickup system because it’s easy that way.) The CoinCounter option on my Money script is using the UI Text from the Canvas. I would really appriciate any help i can get!
Money script (c#):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Money : MonoBehaviour {
private int moneyAmount;
[SerializeField]
private Text coinCounter;
// Use this for initialization
void Start () {
moneyAmount = 0;
}
// Update is called once per frame
void Update () {
coinCounter.text = "coins: " + moneyAmount.ToString();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.GetComponent<Money>() )
{
moneyAmount += 1;
Destroy(collision.gameObject);
}
}
}
And yes, i AM using the Coins collisions hitbox as Triggers.