Im new to unity, and i was coding and i got this error: error “Assets\mouselook.cs(21,26): error CS1002: ; expected”, i cant find the problem with the script, so i dont know how to fix it, here is my code:
public class mouselook : MonoBehaviour
{
public float MouseSensivity = 100f;
public Transform playerBody;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis(“Mouse X”) * MouseSensivity * Time.deltaTime;
float mouseY = Input.GetAxis(“Mouse Y”) * MouseSensivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf,Clamp(xRotation, -90f, -90f);
transform.localRotation = Quaterion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
Putcho
March 25, 2021, 5:27pm
2
use code tag when you show your script on the forum so other can read
If you see someone who needs to know about code tags, please link them to this post:
Please use code tags when posting code.
You can "tag" your code by typing [984347--130826--Screenshot 2015-03-16 10.33.58.png] around your code.
There is no overt "Code" tag button that automatically tags a selection as code.
That being said, however, we can Insert code directly into the post using the "Insert Code" button:
[image]
This will bring up an "Insert" window were we can paste our code and c…
As has been said, use code tags - this makes it easy for everyone to find the correct line and read your code properly.
Aside from that, this is most likely your problem:
Mathf,Clamp should be Mathf.Clamp
1 Like
Putcho
March 25, 2021, 5:32pm
4
Manuovni:
Im new to unity, and i was coding and i got this error: error “Assets\mouselook.cs(21,26): error CS1002: ; expected”, i cant find the problem with the script, so i dont know how to fix it, here is my code:
public class mouselook : MonoBehaviour
{
public float MouseSensivity = 100f;
public Transform playerBody;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis(“Mouse X”) * MouseSensivity * Time.deltaTime;
float mouseY = Input.GetAxis(“Mouse Y”) * MouseSensivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf,Clamp(xRotation, -90f, -90f);
transform.localRotation = Quaterion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
1: you didn’t declears xRotation variables
2: is not Mathf**,Clamp you use Mathf .**Clamp
3. is not Quaterion, its Quaternion
public class mouselook : MonoBehaviour
{
public float MouseSensivity = 100f;
public Transform playerBody;
private float xRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * MouseSensivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * MouseSensivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, -90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
And probably more… if you’re going to type in code, it has to be 100% correct.
That means:
perfect spelling
perfect capitalization (or lack)
perfect punctuation
perfect spacing (or lack of spacing)
If any of 1,2, or 3 are wrong, it won’t work. Often times if 4 is wrong, it also might not work.
Manuovni:
“Assets\mouselook.cs(21,26): error CS1002: ; expected”, i cant find the problem with the script, so i dont know how to fix it, here is my code:
How to understand compiler and other errors and even fix them yourself:
https://discussions.unity.com/t/824586/8
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: https://discussions.unity.com/t/481379
1 Like