Can You Guys Help me with this error in my code below? Because I can’t get rid of this error, Also I can’t Get rid of it because I’m a starter to C#.
My Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour;
{
public RigidBody rb;
public float ForwardForce = 2000f;
public float BackwardsForce = -2000f;
public float JumpForce = 1000f;
// Update is called once per frame
void Update ()
{
if ( Input.GetKey("right") )
{
rb.AddForce(ForwardForce * Time.deltaTime, 0, 0);
}
if ( Input.GetKey("left") )
{
rb.AddForce(BackwardsForce * Time.deltaTime, 0, 0);
}
if ( Input.GetKey("vbKeySpace") )
{
rb.AddForce(0, JumpForce * Time.deltaTime, 0);
}
}
}
In this case it just draws your attention to line 5… the problem is you have added a semicolon at the end of that line. Remove it.
ALSO:
do physics stuff inside of FixedUpdate() or else your apps behavior will change with framerate changes
do not use Time.deltaTime when giving forces, for the same reason.
All the above is in the docs for the Unity physics system. You probably want to start with some existing physics example codes so you can get a feel for how things work.