Orb of experience(s)

This commit is contained in:
2023-10-10 16:30:12 +02:00
parent 2abdb96912
commit ae38582ddc
15 changed files with 511 additions and 6 deletions
+40
View File
@@ -0,0 +1,40 @@
using UnityEngine;
[RequireComponent(typeof(PlayerManager))]
public class PlayerCollisions : MonoBehaviour
{
private PlayerManager _pm;
private void Start()
{
_pm = GetComponent<PlayerManager>();
}
private void OnTriggerStay2D(Collider2D collision)
{
/** --- Orb Absorber ------------------------------- */
if (collision.gameObject.CompareTag("Orb"))
{
GameObject orb = collision.gameObject;
orb.transform.position = Vector3.MoveTowards(orb.transform.position, transform.position, 1f * Time.deltaTime);
if (orb.transform.position == transform.position)
{
Destroy(orb);
}
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Orb"))
{
GameObject orb = collision.gameObject;
if (orb.transform.position == transform.position)
{
_pm.AddExperience((int)orb.GetComponent<OrbStats>().OrbValue);
}
}
}
}