I need to set the clear flags of the player’s camera to black when I display the sniper sight. I have written a script however it throws the exception ’ The name `cam’ does not exist in the current context’.
script;
using UnityEngine;
using System.Collections;
public class awpScopeIn : MonoBehaviour {
public Texture scopeGUI;
private bool _isScoped = false;
public Color color = Color.black;
void Start()
{
Camera cam = GetComponentInParent( typeof(Camera) ) as Camera;
cam.clearFlags = CameraClearFlags.SolidColor;
}
void OnGUI()
{
float width = 600;
float height = 600;
if (_isScoped) {
GUI.DrawTexture (new Rect ((Screen.width / 2) - (width/2), (Screen.height / 2) - (height/2), width, height), scopeGUI);
}
}
void Update()
{
if(Input.GetButtonDown("Fire2"))
{
_isScoped = !_isScoped;
cam.backgroundColor = color;
}
}
}