C
C#11mo ago
Chopsuy

✅CS1513 '}' expected

can someone help me with solving this?
No description
No description
21 Replies
Chopsuy
ChopsuyOP11mo ago
I was trying to stop an object from rotating with the transform.rotation and the defaultRotate
many things
many things11mo ago
remove all methods and add one by one, that's one thing you can try
Chopsuy
ChopsuyOP11mo ago
you mean Start() and Update()?
many things
many things11mo ago
even the class, eventually if you auto-format the file what does come out?
Chopsuy
ChopsuyOP11mo ago
how do u do that
many things
many things11mo ago
oh you're missing namespace ............. { after usings
Chopsuy
ChopsuyOP11mo ago
like that?
No description
many things
many things11mo ago
using UnityEngine;

+namespace YourNamespace;

public class PlayerMovement ... {
using UnityEngine;

+namespace YourNamespace;

public class PlayerMovement ... {
is this clear?
Chopsuy
ChopsuyOP11mo ago
what does it do?
many things
many things11mo ago
it's to give a name of the location where you are putting your code so in this case the full name of the class would be YourNamespace.PlayerMovement
cap5lut
cap5lut11mo ago
the problem is actually the public static member in the Start() method, u can only declare members at class level
Chopsuy
ChopsuyOP11mo ago
oh
many things
many things11mo ago
aaaaa i missed that i thought "weird, namespace should be implicit"
Chopsuy
ChopsuyOP11mo ago
that works
No description
Chopsuy
ChopsuyOP11mo ago
i named it globalos because i already had a class named globals
cap5lut
cap5lut11mo ago
u could also just make it a static field for PlayerMovement
Chopsuy
ChopsuyOP11mo ago
i don't even know what that is
cap5lut
cap5lut11mo ago
public class PlayerMovement : MonoBehaviour
{
public static Quaternion defaultRotate;
private void Start()
{
// ...
}
private void Update()
{
// ...
}
}
public class PlayerMovement : MonoBehaviour
{
public static Quaternion defaultRotate;
private void Start()
{
// ...
}
private void Update()
{
// ...
}
}
Chopsuy
ChopsuyOP11mo ago
thanks its working
cap5lut
cap5lut11mo ago
and usually u would probably make it readonly and set it its value directly public static readonly Quaternion DefaultRotate = ....;
Chopsuy
ChopsuyOP11mo ago
yea but i think that i will leave it as it is cuz after that ill try to rotate the player not stop him from doing that

Did you find this page helpful?