Search Unity

Question code problom

Discussion in 'Scripting' started by Nehoray_Dadosh, Apr 22, 2021.

  1. Nehoray_Dadosh

    Nehoray_Dadosh

    Joined:
    Apr 21, 2021
    Posts:
    1
    when i try to do a rotate script do my skin its do to my an error and dont working
    **its for camera controllers**

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class CameraControllers : MonoBehaviour
    {
    [SerializeField] private float mouseSensitivity;

    private Transform parent;

    private void start()
    {
    parent = transform.parent;
    Cursor.lockState = CursorLockMode.Locked;
    }

    private void Update()
    {
    Rotate();
    }

    private void Rotate()
    {
    float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    parent.Rotate(Vector3.up, mouseX);
    }
    }​
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    This is actually not helpful.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    How to understand compiler and other errors and even fix them yourself:

    https://forum.unity.com/threads/ass...3-syntax-error-expected.1039702/#post-6730855

    If you post a code snippet, ALWAYS USE CODE TAGS:

    How to use code tags: https://forum.unity.com/threads/using-code-tags-properly.143875/

    Also, consider this:
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Everything @Kurt-Dekker said is true.
    However, as I was scrolling down, I did see at a glance a glaring issue.

    Methods should always start with a capital letter. Get in this habit. Especially when they are one of Unity's magic methods.
    start() should be Start()
     
    Last edited: Apr 22, 2021
    Sphinks and Kurt-Dekker like this.
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This ^^^

    Start() and start() are different method names. So the error you're getting is likely a null reference error inside the Rotate method because start() is never run to set "parent".
     
    a4chteam likes this.