Question by
Cronoss95 · Aug 23, 2020 at 08:02 PM ·
physicscoinscollections
Collectables count to much
Hello!
I am currently trying to implement currency in my game, so that the player can buy upgrades. Everything works fine, but sometimes, the coins count too much. One coin is supposed to be 1. But when I add rigidbody2d and another collider (that is NOT a trigger) for the physics, the coins sometimes count 2.
When they dont habe physics and just float, everything is fine. But I really like to have the coins to bounce on the ground, when an enemy is destroyed. Could somebody help me here?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Money : MonoBehaviour
{
public GameObject anvilOfArgosBlocker;
//Hier erstellen wir Collectables, die A) von Gegnern fallen B) aufgesammelt werden C) für Upgrades benötigt werden D) sichtbar gezählt werden können
[SerializeField]
private int moneyAmount;
// Upgrades Blockers (liegen vor dem Kaufbutton
void Start()
{
moneyAmount = 0; //Anfangs kein Geld zur Verfügung
//Hier Blocker aktivieren
anvilOfArgosBlocker.SetActive(true);
}
void Update()
{
if (moneyAmount>=6) //ANVIL OF ARGOS (>= Größer oder Gleich
{
anvilOfArgosBlocker.SetActive(false);
}
else
{
anvilOfArgosBlocker.SetActive(true);
}
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Coins"))
{
collision.gameObject.SetActive(false);
moneyAmount = moneyAmount + 1;
}
}
public int getMoney()
{
return moneyAmount;
}
public void anvilOfArgos()
{
moneyAmount -= 6;
}
}
Comment