Search Unity

Can someone help me with this error?

Discussion in 'Scripting' started by fatmario565, Jul 25, 2014.

  1. fatmario565

    fatmario565

    Joined:
    Feb 26, 2014
    Posts:
    4
    I am new to unity and I am making my first game, I came across this error and I have no idea what it means.

    Error:
    Assets/first person/NewBehaviourScript.cs(24,45): error CS0176: Static member `UnityEngine.Camera.main' cannot be accessed with an instance reference, qualify it with a type name instead



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.  
    6.     public float movemetspeed = 5.0f;
    7.     public float mousesensitivity = 5.0f;
    8.     public float updwnrange = 80.0f;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.         //rotation
    18.  
    19.         float rotX = Input.GetAxis ("Mouse X") * mousesensitivity;
    20.         transform.Rotate (0, rotX, 0);
    21.  
    22.         float rotupdwn = Input.GetAxis ("Mouse Y") * mousesensitivity;
    23.  
    24.         float currentupdwn = camera.main.transform.rotation.eulerAngles.x;
    25.         float desiredupdwn = currentupdwn - rotupdwn;
    26.  
    27.         Camera.main.transform.rotation = Quaternion.Euler (desiredupdwn, 0, 0);
    28.  
    29.         //movement
    30.         float forwardspeed = Input.GetAxis ("Vertical") * movemetspeed;
    31.         float sidespeed = Input.GetAxis ("Horizontal") * movemetspeed;
    32.  
    33.         Vector3 speed = new Vector3 (sidespeed, 0, forwardspeed);
    34.  
    35.         speed = transform.rotation * speed;
    36.  
    37.         CharacterController cc = GetComponent<CharacterController>();
    38.  
    39.         cc.SimpleMove (speed);
    40.     }
    41. }//
    42.  
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    camera.main isn't the same thing as Camera.main. Note the capital C
     
  3. fatmario565

    fatmario565

    Joined:
    Feb 26, 2014
    Posts:
    4
    thanks for that.