2022-10-29 22:49:26 -04:00

40 lines
840 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collectible : MonoBehaviour
{
[SerializeField]
private int amount;
[SerializeField]
private float rotSpeed;
[SerializeField]
private float timeToAppear;
void Update()
{
transform.Rotate(0, rotSpeed, 0, Space.World);
}
private void OnTriggerEnter(Collider other) {
if(other.gameObject.tag.Equals("Player")){
GameController.Instance.AddCoins(amount);
Vanish();
}
}
private void Vanish(){
gameObject.SetActive(false);
if(timeToAppear > -1){
Invoke("Appear", timeToAppear);
}else{
Destroy(this.gameObject);
}
}
private void Appear(){
gameObject.SetActive(true);
}
}