Question by
holonick · Mar 18, 2017 at 08:54 AM ·
c#unity 5camerascripting beginner
How to access camera Dont Clear in camera clear flags using c#
Hello, Im trying to create a public void that I can then attach to a key or button. The public void, I want it to access the cameras clear flags function and select "dont clear". Then with another public void to switch it back to solid background. Im not much of a c# person and Im using what the unity docs say but its just confusing...due to my weak knowledge of c# basics.
Anyway, this is what I have so far...
using UnityEngine; using System.Collections;
public class CamClear : MonoBehaviour {
public GameObject cam;
// Use this for initialization
void Start () {
GetComponent<Camera>() = GetComponent<Camera>();
GetComponent<Camera>().clearFlags = CameraClearFlags.Nothing;
}
// Update is called once per frame
void Update () {
}
public void DontClear(){
cam.GetComponent<Camera>().clearFlags = true;
}
}
Comment
Best Answer
Answer by Hellium · Mar 18, 2017 at 08:55 AM
public class CamClear : MonoBehaviour {
private Camera cam;
void Awake ()
{
cam = GetComponent<Camera>();
}
public void DontClear()
{
cam.clearFlags = CameraClearFlags.Nothing;
}
public void SolidColor()
{
cam.clearFlags = CameraClearFlags.SolidColor;
}
}