씬이 전환될 때 효과를 주어 부드럽게 넘어가도록 효과 추가
//public SceneAsset scene; public Image fadeImage; public float fadeDuration = 1.5f; private static SceneChanger instance; private void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } public void StartButton() { //if (scene != null) //{ //SceneManager.LoadScene("stage1"); LoadSceneWithFade("stage1"); //} } public void LoadGame() { string savedStage = PlayerPrefs.GetString("SavedStage", "Stage1"); //SceneManager.LoadScene(savedStage); LoadSceneWithFade(savedStage); } public void GoToTitle() { SaveGame(); //SceneManager.LoadScene("TitleScene"); LoadSceneWithFade("TitleScene"); } private void SaveGame() { string currentScene = SceneManager.GetActiveScene().name; PlayerPrefs.SetString("SavedStage", currentScene); PlayerPrefs.Save(); } public void NextStage() { string currentScene = SceneManager.GetActiveScene().name; string nextScene = ""; if (currentScene == "Stage1") nextScene = "Stage2"; else if (currentScene == "Stage2") nextScene = "Stage3"; else if (currentScene == "Stage3") nextScene = "TitleScene"; //SceneManager.LoadScene(nextScene); LoadSceneWithFade(nextScene); } public void LoadSceneWithFade(string scene) { StartCoroutine(FadeOutAndLoadScene(scene)); } private IEnumerator FadeOutAndLoadScene(string sceneName) { float elapsedTime = 0f; Color color = fadeImage.color; // 페이드 아웃 효과 while (elapsedTime < fadeDuration) { elapsedTime += Time.deltaTime; color.a = Mathf.Lerp(0, 1, elapsedTime / fadeDuration); fadeImage.color = color; yield return null; } SceneManager.LoadScene(sceneName); // 페이드 인 효과 (Optional) elapsedTime = 0f; while (elapsedTime < fadeDuration) { elapsedTime += Time.deltaTime; color.a = Mathf.Lerp(1, 0, elapsedTime / fadeDuration); fadeImage.color = color; yield return null; } } public void Exit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif }
public float playerRange = 5f; public float arrowSpeed = 5f; public float maxDistance = 15f; public float damage = 20f; private GameObject player; private bool isFlying = false; private Vector3 startPosition; void Start() { player = GameObject.FindGameObjectWithTag("Player"); startPosition = transform.position; } void Update() { DetectAndShoot(); HandleArrowMovement(); } private void DetectAndShoot() { if (!isFlying && player != null) { float distanceToPlayer = Mathf.Abs(player.transform.position.x - transform.position.x); if (distanceToPlayer <= playerRange) { isFlying = true; } } } private void HandleArrowMovement() { if (isFlying) { transform.Translate(Vector3.right * arrowSpeed * Time.deltaTime); if (Vector3.Distance(startPosition, transform.position) >= maxDistance) { Destroy(gameObject); } } } private void OnTriggerEnter2D(Collider2D collision) { // 플레이어와 충돌 처리 if (collision.CompareTag("Player")) { // 플레이어에게 데미지를 준다 PlayerInfo playerInfo = player.GetComponent<PlayerInfo>(); if (playerInfo != null) { playerInfo.health -= damage; } // 화살 파괴 Destroy(gameObject); } }