- Home /
Question by
Misthra-Games · Apr 29, 2016 at 03:51 AM ·
c#camerafieldofview
object refer error
Hey! So Its giving me an error like this:
But the problem is, I'm not trying to reference any objects. Heres my code:
using UnityEngine;
using System.Collections;
public class fiftyCalScript : MonoBehaviour {
private GameObject pO;
private Player pS;
private crosshair cH;
private GameObject _crossh;
private GameObject primaryH;
private GameObject secondaryH;
private WeaponsAndDamage wAD;
private bool zoomedIn = false;
// Use this for initialization
void Start () {
pO = GameObject.Find ("FPSController");
pS = pO.GetComponent<Player> ();
wAD = pO.GetComponent<WeaponsAndDamage> ();
primaryH = GameObject.Find ("PrimaryHolder");
secondaryH = GameObject.Find ("SecondaryHolder");
_crossh = GameObject.Find ("crossh");
cH = _crossh.GetComponent<crosshair> ();
if (secondaryH.transform.childCount != 1){
gameObject.transform.SetParent (secondaryH.transform);
}
else if (wAD.getSondaryState() && secondaryH.transform.childCount == 1){
gameObject.transform.SetParent (secondaryH.transform);
}
else if (wAD.getPrimaryState() && primaryH.transform.childCount == 1){
gameObject.transform.SetParent (primaryH.transform);
}
}
void Awake() {
}
public void damageOnActive() {
if (gameObject.activeSelf) {
cH.fireRate = 1000f;
cH.semiAuto = true;
cH.automatic = false;
pS.setDamage (700f);
}
}
public void switchFOV() {
if (zoomedIn == false) {
zoomedIn = true;
} else if (zoomedIn == true) {
zoomedIn = false;
}
}
public void CheckFOV() {
if (zoomedIn) {
Camera.current.fieldOfView = 20;
} else if (!zoomedIn) {
Camera.current.fieldOfView = 60;
}
}
//public bool checkActive() {
// return gameObject.activeSelf;
//}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire2")) {
switchFOV ();
}
CheckFOV ();
damageOnActive ();
}
}
why is this Happening??
cameraerror.png
(4.8 kB)
Comment
Answer by sk8terboy4 · Apr 29, 2016 at 04:54 AM
Use Camera.main instead of Camera.current. As stated in the docs: Camera Scripting API
that game me some kind of static area. But i fixed the original problem by using a public variable
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How do i set fov for multiple cameras at once? 1 Answer
Maintain screenspace scale/position as camera field of view changes? 2 Answers
Multiple Cars not working 1 Answer
Pinch zoom 0 Answers