Szenentransition programmiert + letzte Sachen programmiert.
This commit is contained in:
1 parent
9a70ec2926
commit
8cc8ec6ef3
27 files changed
+1969
-367
No files matched your search
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FadeScreen : MonoBehaviour
|
||||
{
|
||||
public bool fadeOnStart = true;
|
||||
public float fadeDuration = 2;
|
||||
public Color fadeColor;
|
||||
private Renderer rend;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rend = GetComponent<Renderer>();
|
||||
if (fadeOnStart)
|
||||
FadeIn();
|
||||
}
|
||||
|
||||
|
||||
public void FadeIn()
|
||||
{
|
||||
Fade(1, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void FadeOut()
|
||||
{
|
||||
Fade(0, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Fade(float alphaIn, float alphaOut)
|
||||
{
|
||||
StartCoroutine(FadeRoutine(alphaIn,alphaOut));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IEnumerator FadeRoutine(float alphaIn, float alphaOut)
|
||||
{
|
||||
float timer = 0;
|
||||
while(timer <= fadeDuration)
|
||||
{
|
||||
Color newColor = fadeColor;
|
||||
newColor.a = Mathf.Lerp(alphaIn,alphaOut,timer / fadeDuration);
|
||||
|
||||
rend.material.SetColor("_Color", newColor);
|
||||
|
||||
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Color newColor2 = fadeColor;
|
||||
newColor2.a = alphaOut;
|
||||
|
||||
rend.material.SetColor("_Color", newColor2);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 291207750a241416aac8bb3852e11f36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class ScreenTransitionManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public FadeScreen fadeScreen;
|
||||
|
||||
|
||||
public void GoToScene(int sceneIndex)
|
||||
{
|
||||
StartCoroutine(GoToSceneRoutine(sceneIndex));
|
||||
|
||||
}
|
||||
|
||||
|
||||
IEnumerator GoToSceneRoutine(int sceneIndex)
|
||||
{
|
||||
|
||||
fadeScreen.FadeOut();
|
||||
yield return new WaitForSeconds(fadeScreen.fadeDuration);
|
||||
|
||||
// Launch the new scene
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void GoToSceneAsync(int sceneIndex)
|
||||
{
|
||||
StartCoroutine(GoToSceneAsyncRoutine(sceneIndex));
|
||||
|
||||
}
|
||||
|
||||
|
||||
IEnumerator GoToSceneAsyncRoutine(int sceneIndex)
|
||||
{
|
||||
|
||||
fadeScreen.FadeOut();
|
||||
|
||||
// Launch the new scene
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
|
||||
operation.allowSceneActivation = false;
|
||||
|
||||
float timer = 0;
|
||||
while(timer >= fadeScreen.fadeDuration && !operation.isDone)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
yield return null;
|
||||
|
||||
}
|
||||
|
||||
operation.allowSceneActivation = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73688ae218a4243df800a46e78831542
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user