142 lines
4.4 KiB
C#
142 lines
4.4 KiB
C#
using System.Collections;
|
|
using System.Drawing;
|
|
using BehaviorDesigner.Runtime.Tasks.Unity.UnityTransform;
|
|
using BlueWater.Audios;
|
|
using UnityEngine;
|
|
using Sirenix.OdinInspector;
|
|
using Color = UnityEngine.Color;
|
|
using Image = UnityEngine.UI.Image;
|
|
|
|
public class TycoonGameOver : MonoBehaviour
|
|
{
|
|
// RectTransform을 통해 UI 오브젝트 위치를 제어
|
|
private RectTransform _shipRectTransform;
|
|
|
|
// 흔들림 강도와 범위 설정
|
|
public float shakeAmount = 0.1f; // 흔들림 강도
|
|
public float shakeLimit = 10f; // 흔들림 제한
|
|
|
|
// 밑으로 이동하는 속도 설정
|
|
public float fallSpeed = 50f; // UI 좌표에서는 보통 작은 값을 사용
|
|
|
|
// 이동 시간을 제어하는 변수들
|
|
private float shakeDuration = 2.0f; // 흔들리기만 하는 시간
|
|
private float fallDuration = 5.0f; // 흔들리며 내려가는 시간
|
|
|
|
// 흔들림 변화 간격
|
|
public float shakeInterval = 0.01f; // 흔들림 변화 주기 (뚝뚝 끊기게 만드는 간격)
|
|
|
|
// 초기 위치 저장
|
|
private Vector2 originalPosition;
|
|
private Vector2 shakeOffset;
|
|
private float shakeTimer = 0f; // 흔들림 타이머
|
|
private Color originalColor; // 원래 색상 저장
|
|
|
|
private GameObject _ship;
|
|
private Image _text;
|
|
|
|
private GameObject _titleBtn;
|
|
private GameObject _retryBtn;
|
|
|
|
void Start()
|
|
{
|
|
_ship = transform.Find("Ship").gameObject;
|
|
_text = transform.Find("Text").GetComponent<Image>();
|
|
|
|
_titleBtn = transform.Find("Title").gameObject;
|
|
_retryBtn = transform.Find("Retry").gameObject;
|
|
|
|
originalColor = _text.color; // 원래 색상 저장 (투명도 포함)
|
|
//_ship = GetComponent.Find("");
|
|
//AudioManager.Instance.SetMasterVolume(1.0f);
|
|
|
|
// RectTransform 가져오기
|
|
_shipRectTransform = _ship.GetComponent<RectTransform>();
|
|
originalPosition = _shipRectTransform.anchoredPosition;
|
|
}
|
|
|
|
[Button("게임오버 시작")]
|
|
public void GameOver_Start()
|
|
{
|
|
// 코루틴 시작
|
|
StartCoroutine(MoveObject());
|
|
}
|
|
|
|
// 코루틴 정의
|
|
IEnumerator MoveObject()
|
|
{
|
|
// 2.0초 동안은 흔들리기만 함
|
|
float timer = 0f;
|
|
while (timer < shakeDuration)
|
|
{
|
|
ShakeObject();
|
|
timer += Time.deltaTime;
|
|
yield return null; // 다음 프레임까지 대기
|
|
}
|
|
|
|
// 그 후 5.0초 동안은 흔들리며 밑으로 내려감
|
|
timer = 0f;
|
|
|
|
// 이미지의 초기 색상과 알파값을 0으로 설정
|
|
Color imageColor = _text.color;
|
|
imageColor.a = 0f;
|
|
_text.color = imageColor;
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
while (timer < fallDuration)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
imageColor.a = Mathf.Clamp01(elapsedTime / fallDuration);
|
|
_text.color = imageColor;
|
|
|
|
MoveDown();
|
|
ShakeObject();
|
|
timer += Time.deltaTime;
|
|
|
|
_titleBtn.SetActive(true);
|
|
_retryBtn.SetActive(true);
|
|
|
|
yield return null; // 다음 프레임까지 대기
|
|
}
|
|
|
|
// 최종적으로 알파값을 1로 설정 (완전히 불투명하게)
|
|
imageColor.a = 1f;
|
|
_text.color = imageColor;
|
|
|
|
}
|
|
|
|
// 흔들림 구현 함수
|
|
void ShakeObject()
|
|
{
|
|
shakeTimer += Time.deltaTime;
|
|
|
|
// 흔들림 타이머가 주기보다 크면 새로운 흔들림 값을 생성
|
|
if (shakeTimer > shakeInterval)
|
|
{
|
|
// 새로운 무작위 흔들림 값 생성
|
|
float offsetX = Random.Range(-shakeLimit, shakeLimit);
|
|
float offsetY = Random.Range(-shakeLimit, shakeLimit);
|
|
|
|
// 새로운 흔들림 값을 저장
|
|
shakeOffset = new Vector2(offsetX, offsetY);
|
|
|
|
// 타이머 초기화
|
|
shakeTimer = 0f;
|
|
}
|
|
|
|
// 현재 오브젝트의 좌표를 흔들림 값으로 업데이트
|
|
_shipRectTransform.anchoredPosition = originalPosition + shakeOffset;
|
|
}
|
|
|
|
// 밑으로 내려가는 함수
|
|
void MoveDown()
|
|
{
|
|
// 점점 밑으로 내려가는 부분 (Y 축 감소, anchoredPosition 사용)
|
|
originalPosition.y -= fallSpeed * Time.deltaTime;
|
|
|
|
// 현재 오브젝트 위치도 업데이트
|
|
_shipRectTransform.anchoredPosition = originalPosition+ shakeOffset;
|
|
}
|
|
|
|
} |