Search Unity

Resolved Mouse look script error.

Discussion in 'Scripting' started by NotNikto, Jan 18, 2021.

  1. NotNikto

    NotNikto

    Joined:
    Jan 17, 2021
    Posts:
    8
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mouselook : MonoBehaviour
    6. {
    7.  
    8.     public float mouseSensitivity = 100f;
    9.  
    10.     public Transform playerbody;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.  
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    22.         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    23.  
    24.         playerBody.Rotate(Vector3.up * mouseX)
    25.     }
    26. }
    The error screenshot is a attached to this thread too.
     

    Attached Files:

  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    The error points to line 24, char 47. But knowing the line number is enough to get your attention to the line. You are missing a ; at the end of line 24, which is exactly what the error tells you. :)
     
  3. NotNikto

    NotNikto

    Joined:
    Jan 17, 2021
    Posts:
    8
    Thank you so much! Now there is another one:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mouselook : MonoBehaviour
    6. {
    7.  
    8.     public float mouseSensitivity = 100f;
    9.  
    10.     public Transform playerbody;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.  
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    22.         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    23.  
    24.         playerBody.Rotate(Vector3.up * mouseX);
    25.     }
    26. }
    e9c331df1be5654dbeedc1faf40d044f.png
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    I do think if you check your code a bit, you'll solve many of these as normal debugging. Note, caps matters. So check out the line it points to and then look at your declared transform variable.
     
  5. NotNikto

    NotNikto

    Joined:
    Jan 17, 2021
    Posts:
    8
    Thank you, now it works. I will in the future take a closer look before posting on here.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    We all have to learn these things. Just trying to help you out so you don't have to rush here for every error (and thus slow down your production). The error codes are pretty helpful when it comes to syntax errors.