Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLock : MonoBehaviour
{
 
    public float mouseSensitivity = 100f;

    public Transform playerBody; 
 
    float xRotation = 0f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float mouseX = Input.GetAxis("MouseX") = mouseSensitivity = Time.deltaTime;
        float mouseY = Input.GetAxis("MouseY") = mouseSensitivity = Time.deltaTime;

        xRotation -= mouseY;

        transform localRotation = Quaternion.Euler(xRotation, 0f, 0f);
        playerBody.Rotate(Vector3.up = mouseX);
    }
}


What I have tried:

watching video's and asking help from coders.
Posted
Updated 10-Sep-22 4:46am
v2
Comments
Dave Kreskowiak 10-Sep-22 10:43am    
Nobody gives a sh*t about the error number. ALWAYS give the complete error message you get and the line that's throwing it.
Yvonne Bonthuis 10-Sep-22 11:01am    
i dont know the line thats trowing it

1 solution

These two lines make no sense at all:
C#
float mouseX = Input.GetAxis("MouseX") = mouseSensitivity = Time.deltaTime;
float mouseY = Input.GetAxis("MouseY") = mouseSensitivity = Time.deltaTime;

Why are there THREE assignment operators on a single line? I have no idea what you're trying to do, but a rule of thumb is you only use ONE assignment operator on a line if you want to write readable, and DEBUGGABLE, code.
 
Share this answer
 
Comments
Yvonne Bonthuis 10-Sep-22 11:13am    
hey Dave Kreskowiak. this is my first game, and im following a basic youtube tutorial. so what are the assignments operators in the lines? thank you.
Dave Kreskowiak 10-Sep-22 12:27pm    
No, you're going to follow any YouTube "tutorials". They don't teach as most people who make those video's have no idea HOW to teach.

Assuming you're using Unity, get a book on C# and Unity.

The fact that you're asking me what an assignment operator is is proof you need to learn the very basics of C#, so go get that book. You've got plenty to choose from: https://www.google.com/search?q=c%23+unity+books

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900