83 lines
2.2 KiB
C#
83 lines
2.2 KiB
C#
using System;
|
|
using BlueWater.Audios;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class Mushroom : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
private float _playerHoldingTime = 3f;
|
|
|
|
[SerializeField]
|
|
private Sprite _heartSprite;
|
|
|
|
[SerializeField]
|
|
private string _cleaningSfxName = "CleaningFloor";
|
|
|
|
private bool _isPlayerInteracting;
|
|
|
|
private void Update()
|
|
{
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
TycoonManager.Instance.TycoonStatus.CurrentPlayerHealth++;
|
|
|
|
Destroy();
|
|
}
|
|
|
|
float playerHoldingDeltaTime = Time.deltaTime / _playerHoldingTime;
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += playerHoldingDeltaTime;
|
|
}
|
|
else
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= playerHoldingDeltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
InteractionCanvas.BalloonUi.ShowUi();
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = true;
|
|
_isPlayerInteracting = true;
|
|
AudioManager.Instance.PlaySfx(_cleaningSfxName);
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
_isPlayerInteracting = false;
|
|
AudioManager.Instance.StopSfx(_cleaningSfxName);
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything();
|
|
}
|
|
|
|
private void Destroy()
|
|
{
|
|
if (_isPlayerInteracting)
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
}
|
|
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
} |