So I have recently started to learn how to progam in unity with C#.And I have been having some issues with being able to move a object (named player) with WSAD (like I am not able to move the object at all).The two errors are
Assets\ wasd1.cs(13,6):error CS1513: } expected
and
Assets\wasd1e.cs(30,1): error CS1022: Type or namespace definition, or end-of-file expected
The code for the key bindings are:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddComponetExample : Rigidbody
{
}
public class Wasd1e : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
public GameObject player;
}
// Update is called once per frame
void Update()
{
Rigidbody rb = GetComponent<Rigidbody>();
if (Input.GetKey(KeyCode.A))
rb.AddForce(Vector3.left);
if (Input.GetKey(KeyCode.D))
rb.AddForce(Vector3.right);
if (Input.GetKey(KeyCode.W))
rb.AddForce(Vector3.up);
if (Input.GetKey(KeyCode.S))
rb.AddForce(Vector3.down);
}
}
The code for the movement is
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public GameObject player;
CharacterController characterController;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
if (characterController.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
characterController.Move(moveDirection * Time.deltaTime);
}
}
So how should I fix the code in order for the WSAD keys to move the object?
Thank you for your time reading this