This code doesn't work

I have this code but when I play it inputs don’t work. I tried to put a log in the start and it works.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerControl : MonoBehaviour
{
public float MoveVelocity = 10;
Rigidbody PlayerRigidbody;
GameObject PlayerCamera;
void Start()
{
PlayerCamera = GameObject.Find(“PlayerCamera”);
PlayerRigidbody = GetComponent();
}
void Udpate()
{
if (Input.GetKey(KeyCode.W))
{
MoveForward();
}
if (Input.GetKey(KeyCode.S))
{
MoveBackwards();
}
if (Input.GetKey(KeyCode.A))
{
MoveLeft();
}
if (Input.GetKey(KeyCode.D))
{
MoveRight();
}
}
void MoveForward()
{
PlayerRigidbody.AddForce(PlayerCamera.transform.forward * MoveVelocity * Time.deltaTime);
}
void MoveBackwards()
{
PlayerRigidbody.AddForce(-PlayerCamera.transform.forward * MoveVelocity * Time.deltaTime);
}
void MoveLeft()
{
PlayerRigidbody.AddForce(-PlayerCamera.transform.right * MoveVelocity * Time.deltaTime);
}
void MoveRight()
{
PlayerRigidbody.AddForce(PlayerCamera.transform.right * MoveVelocity * Time.deltaTime);
}
}

You spelled Update wrong (Udpate). And since you’re adding force, that should go in FixedUpdate instead of Update.

Also, please use Code tags when posting code.

4 Likes

Thanks, it works now