- Home /
My Movement Script won't work!,my movement script won't work!
so i just created my first movement script following a tutorial and after finishing it i imported in unity and i got a couple of errors with the code its quite simple to put some symbols but don't say what line is the problem or i just don't know where it says.... can someone help me??
Here is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public float walkSpeed; public class Movement : MonoBehaviour { // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey("w")) {
transform.position += transform.TransformDirection(Vector3.foward) * Time.deltaTime * movementSpeed; * 2.5f;
{ } else if(Input.GetKey("w")) && !Input.GetKey(KeyCode.LeftShift)) { }
transform.position += Transform.TransformDirection(Vector3.fwd) * Time.DeltaTime * MovementSpeed;
} else if (Input.Getkey("s")) {
transform.position -= transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
}
if(Input.GetKey("a") && !Input.GetKey("d")) {
transform.position += transform.TransformDirection(Vector3.Left) * Time.deltaTime * movementSpeed;
} else if (Input.GetKey("d") && !Input.GetKey("a")) {
transform.position -= transform.TransformDirection(Vector3.left) * Time.deltaTime * movementSpeed;
}
,so i just created my first movement script following a tutorial and after finishing it i imported in unity and i got a couple of errors with the code its quite simple to put some symbols but don't say what line is the problem or i just don't know where it says.... can someone help me??
Here is my code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public float walkSpeed; public class Movement : MonoBehaviour { // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey("w")) {
transform.position += transform.TransformDirection(Vector3.foward) * Time.deltaTime * movementSpeed; * 2.5f;
{ } else if(Input.GetKey("w")) && !Input.GetKey(KeyCode.LeftShift)) { }
transform.position += Transform.TransformDirection(Vector3.fwd) * Time.DeltaTime * MovementSpeed;
} else if (Input.Getkey("s")) {
transform.position -= transform.TransformDirection(Vector3.forward) * Time.deltaTime * movementSpeed;
}
if(Input.GetKey("a") && !Input.GetKey("d")) {
transform.position += transform.TransformDirection(Vector3.Left) * Time.deltaTime * movementSpeed;
} else if (Input.GetKey("d") && !Input.GetKey("a")) {
transform.position -= transform.TransformDirection(Vector3.left) * Time.deltaTime * movementSpeed;
}
Answer by logicandchaos · Feb 02, 2021 at 01:26 AM
Actually it says exactly where to put the missing symbols in the error message. You are opening brackets and not closing them and even opening and closing them with no code in between. For every { there must be a } for every [ there must be a ] for every ( there must be a ) these are used to contain and separate code and control scope. If you don;t understand that you need to learn more about C# there are many tutorials online. Here are a few:
intro to C# https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/
learn C# in 4 hours https://www.youtube.com/watch?v=GhQdlIFylQ8&t=473s&fbclid=IwAR26QfJjvv9_eCK_W8aSZEFRFydoSg7DzO9wC2cObej5UpAyoqgViL3WFPM
solo learn c# https://www.sololearn.com/Course/CSharp/?fbclid=IwAR05ae_uvFM1up2k7A0oqOFUZomFCsI8k_JGdueUOG5cZKoB4t5-3-FdR0I