- Home /
Question by
CoolCasualCat · Jul 15, 2015 at 10:53 AM ·
c#guicanvas
So I'm pretty new to the Unity Engine as well as scripting in C#, but I need help with figuring out how to make a canvas appear when my player leaves the camera screen.
sing UnityEngine; using UnityEngine.UI; using System.Collections;
public class PlayeyLose : MonoBehaviour { public Canvas gameOver;
void Start ()
{
gameOver = GetComponent<Canvas> ();
gameOver.enabled = false;
}
void OnBecameInvisible()
{
Time.timeScale = 0f;
gameOver.enabled = true;
}
}
Comment
If you are assigning in inspector the canvas don't use GetComponent. You are probably overriding it with null here.
Wiki
Answer by Narendraom · Jul 15, 2015 at 12:22 PM
edit your code..
public class PlayeyLose : MonoBehaviour {
public Canvas gameOver;
void Start ()
{
gameOver.enabled = false;
}
void OnBecameInvisible()
{
Time.timeScale = 0f;
gameOver.enabled = true;
}
}
assign your canvas to gameover object in inspector.