Hi, I want to make the whole game scene fade to white (or flash to white) when the player hits a mine, And then it transitions to game over scene.
I found several tutorial but they all consists of using GUITexture, which I can’t find in Unity 4.6…help?
Yep the new UI is the way to go. Add a canvas and add a panel to that canvas.
Leave the panels default color (should be white) but set the panels alpha to 255.
Add a CanvasGroup to the base canvas. Set its alpha to 0 and untick interactable and blocksRaycast.
Create a HitMine script I’ll use C#
using UnityEngine.UI; // add to the top
// create a public CanvasGroup
public CanvasGroup myCG;
private bool flash = false;
void Update ()
{
if (flash)
{
myCG.alpha = myCG.alpha - Time.deltaTime;
if (myCG.alpha <= 0)
{
myCG.alpha = 0;
flash = false;
}
}
}
Public void MineHit ()
{
flash = true;
myCG.alpha = 1;
}
Sorry for any typo’s, on my phone!
EDIT
This is the full script:
using UnityEngine;
using UnityEngine.UI; // add to the top
using System.Collections;
public class FlashBang : MonoBehaviour {
public CanvasGroup myCG;
private bool flash = false;
void Update ()
{
if (flash)
{
myCG.alpha = myCG.alpha - Time.deltaTime;
if (myCG.alpha <= 0)
{
myCG.alpha = 0;
flash = false;
}
}
}
public void MineHit ()
{
flash = true;
myCG.alpha = 1;
}
}
for testing I added a separate canvas and put a button on it and linked the OnClick to the script on the other, hidden canvas that had the script on it, it calls the MineHit function when clicked.
@AbnerWei… canvasgroup is a component so at your base canvas add a component of canvas group then assign it to public CanvasGroup MyCG…