mirror of
https://github.com/Kizuren/ShantiManti.git
synced 2026-01-03 21:25:45 +01:00
Bug 1: After clearing the data, the game wouldn't save afterwards. Bug 2: Animation was too short, which led to some animation errors
52 lines
No EOL
1.4 KiB
C#
52 lines
No EOL
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SC_2DCoin : MonoBehaviour
|
|
{
|
|
//Keep track of total picked coins (Since the value is static, it can be accessed at "SC_2DCoin.totalCoins" from any script)
|
|
public static int totalCoins = 0;
|
|
public static bool playCoinSound = false;
|
|
|
|
//Coin Cooldown
|
|
private bool canPickUp = true;
|
|
public float pickUpCooldown = 0.1f;
|
|
|
|
void Awake()
|
|
{
|
|
//Make Collider2D as trigger
|
|
GetComponent<Collider2D>().isTrigger = true;
|
|
totalCoins = PlayerSaving.coins;
|
|
}
|
|
|
|
void OnTriggerEnter2D(Collider2D c2d)
|
|
{
|
|
if (canPickUp && (c2d.CompareTag("Player") || c2d.CompareTag("Bullet")))
|
|
{
|
|
canPickUp = false; // Disable picking up coins temporarily
|
|
|
|
totalCoins++;
|
|
|
|
playCoinSound = true;
|
|
Destroy(gameObject);
|
|
|
|
// Start the cooldown coroutine
|
|
StartCoroutine(CoinPickUpCooldown());
|
|
}
|
|
}
|
|
|
|
IEnumerator CoinPickUpCooldown()
|
|
{
|
|
yield return new WaitForSeconds(pickUpCooldown);
|
|
canPickUp = true; //Enable coin pickup again after the cooldown
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (totalCoins != PlayerSaving.coins)
|
|
{
|
|
PlayerSaving.coins = totalCoins;
|
|
PlayerSaving.SavePlayer();
|
|
}
|
|
}
|
|
} |