Trying to create my first movement script by myself, and I’m attempting to assign the value from the variable ‘maxspeed’ to the variable ‘speed’, but my script just doesn’t work. I simply assigned ‘maxspeed’ as a public float and gave it the value ‘25’, then replaced every instance of ‘25’ in my code with ‘maxspeed’.
Here’s my newb noob code:
{
public float speed;
public float maxspeed = 25f;
public string MoveUp = "e";
public string MoveLeft = "s";
public string MoveDown = "d";
public string MoveRight = "f";
void Update()
{
if (Input.GetKey(MoveUp))
{
speed = maxspeed;
transform.Translate(0, 0, speed * Time.deltaTime);
}
if (Input.GetKey(MoveLeft))
{
speed = maxspeed;
transform.Translate(speed * Time.deltaTime, 0, 0);
}
if (Input.GetKey(MoveDown))
{
speed = maxspeed;
transform.Translate(0, 0, -speed * Time.deltaTime);
}
if (Input.GetKey(MoveRight))
{
speed = maxspeed;
transform.Translate(-speed * Time.deltaTime, 0, 0);
}
speed -= 0.05f;
if (speed < 0)
{
speed = 0;
}
}
}