fade not done
This commit is contained in:
parent
54b6c3115c
commit
2708deb2b9
|
@ -0,0 +1,42 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Wait2SecondsToShow : MonoBehaviour
|
||||
{
|
||||
// Reference to the Image component
|
||||
private Image canvas;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
canvas = GetComponent<Image>();
|
||||
StartCoroutine(FadeOut(2f));
|
||||
}
|
||||
|
||||
// Coroutine to fade out the image
|
||||
public IEnumerator FadeOut(float duration)
|
||||
{
|
||||
// Make sure the canvas is not null
|
||||
if (canvas == null)
|
||||
{
|
||||
yield break; // Exit if canvas is not assigned
|
||||
}
|
||||
|
||||
// Starting alpha value (1 is fully opaque)
|
||||
float startAlpha = 1.0f;
|
||||
|
||||
// Elapsed time
|
||||
float time = 0;
|
||||
|
||||
while (time < duration)
|
||||
{
|
||||
time += Time.deltaTime; // Update the time based on the time passed since last frame
|
||||
float alpha = Mathf.Lerp(startAlpha, 0, time / duration); // Calculate the new alpha value
|
||||
canvas.color = new Color(canvas.color.r, canvas.color.g, canvas.color.b, alpha); // Apply the new alpha value to the canvas color
|
||||
yield return null; // Wait for the next frame
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 55f8b539d824ad84cb0f7384c2525a2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue