Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

My script gives errors

Discussion in 'Getting Started' started by TheMadTomato1209, May 10, 2020.

  1. TheMadTomato1209

    TheMadTomato1209

    Joined:
    May 7, 2020
    Posts:
    18
    I wrote this script watching a video (im a total beginner) which is for first person movements, if someone needs it i will link it. When i run my code, i get these errors: mmerror2.PNG
    Here is the code, i didnt copy-paste from a comment or something, i wrote it by watching:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MouseLook : MonoBehaviour
    6. {
    7.     public float mouseSensitivity = 100f;
    8.     float xRotation = 0f;
    9.     public Transform playerBody;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.       Cursor.lockState = CursorLockMode.Locked;
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.       float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    20.       float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    21.  
    22.       xRotation -= mouseY;
    23.       playerBody.Rotate(Vector3.up * mouseX);
    24.      
    25.  
    26.       xRotation = Mathf.Clamp(xRotation, 90f, -90f);
    27.       Transform.localRotation = Quanternion.Euler(xRotation, 0f, 0f);
    28.     }
    29. }
    30.  
    Im still learning, so if possible can you explain why it happens so that i dont mess it up again
     
    Last edited: May 10, 2020
  2. DeanTheodorakis

    DeanTheodorakis

    Joined:
    Apr 29, 2018
    Posts:
    53
    I believe that you just have an error in your spelling of quaternion. there is no 'n' in the first part of the word. (quant should be quat)
     
    TheMadTomato1209 likes this.
  3. TheMadTomato1209

    TheMadTomato1209

    Joined:
    May 7, 2020
    Posts:
    18
    Oh, that means i just didnt see it right. Thank you, tomorrow i will try and tell you. From my opinion the other error seems like is caused from something else, do you know what?
     
  4. DeanTheodorakis

    DeanTheodorakis

    Joined:
    Apr 29, 2018
    Posts:
    53
    no, I'm sorry, I'm not sure what. I have not used quaternions a lot and only caught the typo. I'm not terribly familiar with them otherwise.
     
    TheMadTomato1209 likes this.
  5. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    It's both a typo with "Quanternion" and "Transform".

    "Quanternion" just needs that extra 'n' removed.

    "Transform" should start with a lowercase "t" in order to reference the Transform component attached to the GameObject, because you are currently referencing the Transform class itself.
     
    TheMadTomato1209 likes this.
  6. TheMadTomato1209

    TheMadTomato1209

    Joined:
    May 7, 2020
    Posts:
    18
    Ok thank you i will try!
     
  7. TheMadTomato1209

    TheMadTomato1209

    Joined:
    May 7, 2020
    Posts:
    18
    It works! Thank you!
     
  8. TheMadTomato1209

    TheMadTomato1209

    Joined:
    May 7, 2020
    Posts:
    18
    It works! Thank you so much!