61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System.Collections;
|
|
using BehaviorDesigner.Runtime.Tasks.Unity.UnityGameObject;
|
|
using SoulGames.Utilities;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using Component = System.ComponentModel.Component;
|
|
|
|
namespace DDD.Uis.Tycoon
|
|
{
|
|
public class Buildable : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject GreenArea;
|
|
|
|
private bool IsSpawnEffect = false;
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Update()
|
|
{
|
|
|
|
if (!IsSpawnEffect && Input.GetMouseButtonDown(0))
|
|
{
|
|
IsSpawnEffect = true;
|
|
GreenArea.SetActive(true);
|
|
StartCoroutine(MoveObject());
|
|
|
|
}
|
|
}
|
|
|
|
IEnumerator MoveObject()
|
|
{
|
|
float elapsedTime = 0f;
|
|
Vector3 initialPosition = GreenArea.transform.position;
|
|
Vector3 targetPosition = new Vector3(initialPosition.x, 0.05f, initialPosition.z);
|
|
|
|
while (elapsedTime < 0.5f)
|
|
{
|
|
float easedTime = Mathf.SmoothStep(0f, 1f, elapsedTime / 0.5f);
|
|
GreenArea.transform.position = Vector3.Lerp(initialPosition, targetPosition, easedTime);
|
|
elapsedTime += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
GreenArea.transform.position = targetPosition;
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
elapsedTime = 0f;
|
|
targetPosition = new Vector3(initialPosition.x, -1.5f, initialPosition.z);
|
|
|
|
while (elapsedTime < 0.5f)
|
|
{
|
|
float easedTime = Mathf.SmoothStep(0f, 1f, elapsedTime / 0.5f);
|
|
GreenArea.transform.position = Vector3.Lerp(GreenArea.transform.position, targetPosition, easedTime);
|
|
elapsedTime += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
GreenArea.transform.position = targetPosition;
|
|
GreenArea.SetActive(false);
|
|
}
|
|
}
|
|
} |