2016-07-09 6 views
0

나는 장면 간 페이드 (fade) 방법에 대해 Brackeys (here)에서 자습서를 따랐습니다. 내가 할 수있는 한 최선의 튜토리얼을 따라 갔지만 장면을 실행하면 장면이 페이드 인 (일어나지 않아야 함)하고 단추를 누르면 아무 일도 일어나지 않지만 장면이 바뀌기로되어있다.버튼을 눌렀을 때 새로운 장면이 사라지게하려면 어떻게해야합니까?

내 코드가 잘못되었습니다. 버튼을 눌렀을 때 새로운 장면이 사라지도록 수정하는 방법은 무엇입니까?

changeScene.cs

using UnityEngine; 
using System.Collections; 

public class changeScene : MonoBehaviour { 

public IEnumerator changeToGameScene() { 

    float fadeTime =  GameObject.Find("managerObject").GetComponent<fadeScript>().BeginFade(1); 
    yield return new WaitForSeconds(fadeTime); 
    Application.LoadLevel("gameScene"); 

} 

} 

fadeScript.cs

using UnityEngine; 
using System.Collections; 

public class fadeScript : MonoBehaviour { 


// All Variables 
public Texture2D fadeOutTexture; 
public float fadeSpeed = 0.8f; 

private int drawDepth = -1000; 
private float alpha = 1.0f; 
private int fadeDirection = -1; 

void OnGUI() { 

    alpha += fadeDirection * fadeSpeed * Time.deltaTime; 
    alpha = Mathf.Clamp01(alpha); 

    GUI.color = new Color (GUI.color.r, GUI.color.g, GUI.color.b, alpha); 
    GUI.depth = drawDepth; 
    GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height),  fadeOutTexture); 
} 

public float BeginFade (int direction) { 

    fadeDirection = direction; 
    return (fadeSpeed); 

} 

void OnLevelWasLoaded() { 

    BeginFade (-1); 

} 

} 

답변

1

당신은 화면의 상단에 패널을 배치 시도 할 수 있습니다 : 여기 내 코드입니다. 그런 다음 애니메이터 구성 요소를 사용하여 불투명도가 감소하는 새 애니메이션을 만듭니다. 실제로이 버튼을이 애니메이션으로 호출 할 수 있습니다. 애니메이션이 끝나면 패널을 파괴 할 함수를 호출하는 이벤트를 추가 할 수 있습니다. 도움이 되길 바랍니다.

+0

코드에 대한 도움이 필요했지만 귀하의 방식대로 작동 했으므로 어쨌든 답변을 수락했습니다. :) –