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);
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76eec47d6b942ad4ab792b7022c07bb1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+22
View File
@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerManager : MonoBehaviour
{
public float Health = 100f;
public float Speed = 10f;
public int Exp = 0;
public int Level = 1;
public void AddExperience(int value)
{
Exp += value;
if (Exp >= Level * 10)
{
Exp -= Level * 10;
Level++;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8afe5a349c86994f8ddacd37ce22ae3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: