58 lines
1.4 KiB
C#
58 lines
1.4 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using DG.Tweening;
|
||
|
|
using TMPro;
|
||
|
|
|
||
|
|
public class FractionalCryptoDrop : MonoBehaviour
|
||
|
|
{
|
||
|
|
[System.NonSerialized] public PlayerEntity targetPlayer;
|
||
|
|
|
||
|
|
public enum DropType
|
||
|
|
{
|
||
|
|
DIVI = 0,
|
||
|
|
DOGE = 1,
|
||
|
|
CORE = 2,
|
||
|
|
FLARE = 3,
|
||
|
|
HORDE = 4,
|
||
|
|
NERO = 5,
|
||
|
|
WAX = 6,
|
||
|
|
HAROLD = 7
|
||
|
|
}
|
||
|
|
|
||
|
|
[SerializeField] private DropType dropType;
|
||
|
|
private Vector3 refVelocity;
|
||
|
|
private void Update()
|
||
|
|
{
|
||
|
|
if (targetPlayer == null) { return; }
|
||
|
|
|
||
|
|
if(transform.position.y < -20) { Destroy(gameObject); }
|
||
|
|
|
||
|
|
float distance = Vector3.Distance(transform.position, targetPlayer.transform.position);
|
||
|
|
|
||
|
|
MovementToPlayer(distance);
|
||
|
|
TargetPlayerCollection(distance);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void MovementToPlayer(float distanceToTarget)
|
||
|
|
{
|
||
|
|
if (distanceToTarget <= 16)
|
||
|
|
{
|
||
|
|
transform.position = Vector3.SmoothDamp(transform.position, targetPlayer.transform.position, ref refVelocity, 0.5f);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void TargetPlayerCollection(float distanceToTarget)
|
||
|
|
{
|
||
|
|
if (distanceToTarget <= 2.0f)
|
||
|
|
{
|
||
|
|
//play local sound
|
||
|
|
AudioManager.Instance.PlayOneShotSound("Collect_Fractional_Divi");
|
||
|
|
PacketManager.sendFractionalCryptoCollection(0, (int)dropType);
|
||
|
|
|
||
|
|
//repool after collection
|
||
|
|
Client.Instance.DroppedCryptoInInstance.Remove(this);
|
||
|
|
Destroy(gameObject);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|