• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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:

alt text

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Misthra-Games · Apr 29, 2016 at 05:52 AM 0
Share

that game me some kind of static area. But i fixed the original problem by using a public variable

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

139 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

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

Reverse Camera Twitches 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges