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

Question playerBody

Discussion in 'Scripting' started by UltimtateZippy, Oct 20, 2022.

  1. UltimtateZippy

    UltimtateZippy

    Joined:
    May 21, 2022
    Posts:
    1
    I am new to unity but is it normal that it doesn't show the option to assign a player body.
    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.     float xRotation = 0f;
    13.  
    14.     // Start is called before the first frame update
    15.     void Start()
    16.     {
    17.         Cursor.lockState = CursorLockMode.Locked;
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    24.         float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    25.  
    26.         xRotation -= mouseY;
    27.         xRotation = Mathf.Clamp(xRotation, -90f, 90f)
    28.  
    29.         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f)
    30.         playerBody.Rotate(Vector3.up * mouseX);
    31.     }
    32. }
     

    Attached Files:

  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    This appears to be in the wrong section.
    It shows up in the visual scripting when it's clearly script.
    maybe would get better help on that one
    good luck bud
     
  3. kinitaro

    kinitaro

    Joined:
    May 5, 2023
    Posts:
    1
    I know this is late but you need to assign your playerbody assign it to the parent of your camera upload_2023-5-6_22-38-57.png
     

    Attached Files: