SamsonGame/Assets/Scripts/Game/Loot/LootMoney.cs

53 lines
1.7 KiB
C#

using UnityEngine;
namespace RND
{
public class LootMoney : LootBase
{
public enum MoveTarget { PLAYER = 0, COUNTER = 1, }
[Header("Coin Specific")]
[SerializeField] private MoveTarget _target;
[SerializeField] private SyncCoinsTextType _syncType;
[SerializeField] private int _coinAmount = 1;
protected override void Start()
{
var counter = UI.GetOrCreate<CoinsCounterWindow>();
if (_target == MoveTarget.PLAYER)
{
Transform player = G.Instance.Level.GetPlayerTransform();
Target = player;
TargetOffset = player.GetComponent<Collider>().bounds.center - player.transform.position;
TargetType = MoveTargetType.World;
}
else
{
Target = counter.CoinFlyTarget;
TargetType = MoveTargetType.UI;
}
OnTaken.AddListener(() =>
{
if (_coinAmount > 0)
G.Instance.Session.AddEarnedCoins(_coinAmount);
counter.SyncCoinsCounter(_syncType, false);
Sound.Play("coins_collect");
});
base.Start();
}
public void Init(MoveTarget target, SyncCoinsTextType syncType, bool doJump = false, bool onGround = false,
float delay = 0, bool autoMove = true)
{
_target = target;
_syncType = syncType;
MoveToPicker = false;
JumpType = doJump ? (onGround ? LootJumpType.JumpOnGround : LootJumpType.JumpSingle) : LootJumpType.None;
DropDelay = delay;
AutoMove = autoMove;
}
}
}