Initial commit: Tiny Tackle Heroes Unity project
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using BumpCombat.Constants;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BumpCombat.Progression
|
||||
{
|
||||
[RequireComponent(typeof(Rigidbody2D), typeof(CircleCollider2D))]
|
||||
public sealed class ExperienceOrb : MonoBehaviour
|
||||
{
|
||||
private Rigidbody2D body;
|
||||
private ExperienceSystem experienceSystem;
|
||||
private Transform player;
|
||||
private int value;
|
||||
private bool pickedUp;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
body = GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
experienceSystem = FindAnyObjectByType<ExperienceSystem>();
|
||||
player = experienceSystem != null ? experienceSystem.transform : null;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (player == null || pickedUp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float distance = Vector2.Distance(body.position, player.position);
|
||||
ItemConstants tuning = GameplayConstants.Current.Items;
|
||||
if (distance <= tuning.ExperienceOrbPickupRadius)
|
||||
{
|
||||
pickedUp = true;
|
||||
experienceSystem.CollectExperienceOrb(value);
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (distance <= tuning.ExperienceOrbMagnetRadius)
|
||||
{
|
||||
body.MovePosition(Vector2.MoveTowards(
|
||||
body.position,
|
||||
player.position,
|
||||
tuning.ExperienceOrbMagnetSpeed * Time.fixedDeltaTime));
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize(int experienceValue)
|
||||
{
|
||||
value = Mathf.Max(0, experienceValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user