C
C#8mo ago
Chopsuy

✅CS1513 '}' expected

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

+namespace YourNamespace;

public class PlayerMovement ... {
using UnityEngine;

+namespace YourNamespace;

public class PlayerMovement ... {
is this clear?
Chopsuy
ChopsuyOP8mo ago
what does it do?
FestivalDelGelato
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
cap5lut8mo ago
the problem is actually the public static member in the Start() method, u can only declare members at class level
Chopsuy
ChopsuyOP8mo ago
oh
FestivalDelGelato
aaaaa i missed that i thought "weird, namespace should be implicit"
Chopsuy
ChopsuyOP8mo ago
that works
No description
Chopsuy
ChopsuyOP8mo ago
i named it globalos because i already had a class named globals
cap5lut
cap5lut8mo ago
u could also just make it a static field for PlayerMovement
Chopsuy
ChopsuyOP8mo ago
i don't even know what that is
cap5lut
cap5lut8mo 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
ChopsuyOP8mo ago
thanks its working
cap5lut
cap5lut8mo ago
and usually u would probably make it readonly and set it its value directly public static readonly Quaternion DefaultRotate = ....;
Chopsuy
ChopsuyOP8mo 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?