I want to have an image of my company logo appear when I start the program, and I want to slowly fade to back and then have it load a new scene, does anyone know how to slowly change the transparency of and object?
I think the best solution to your problem is Splash Screen.
You can use a SceneManager.LoadSceneAsync with an animation between the scenes.
This would be the most simple way to do it
Create a C# script, name it ‘FadeOut’ and then drag it on your logo gameObject. Then copy/paste the code and tweak it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class FadeOut : MonoBehaviour
{
[Header("Fade Out Script")]
public Image logoImage;
[Tooltip("Will start the fade out after value (in seconds)")]
public float timeToStartFading = 2f;
[Tooltip("Higher values = faster Fade Out")]
public float fadeSpeed = 1f;
[Tooltip("Scene to Load (Must be stored in Builded Scenes Index -> File/Build Settings...)")]
public int sceneToLoad = 1;
public void Start()
{
//If you didn't drag the component
if (logoImage == null)
logoImage = GetComponent<Image>();
}
public void Update()
{
//Timer
if (timeToStartFading > 0)
{
timeToStartFading -= Time.deltaTime;
return;
}
//Modify the color by changing alpha value
logoImage.color = new Color(logoImage.color.r, logoImage.color.g, logoImage.color.b, logoImage.color.a - (fadeSpeed * Time.deltaTime));
//Basic scene change
if (logoImage.color.a <= 0)
SceneManager.LoadScene(sceneToLoad, LoadSceneMode.Single);
}
}