Player speed doesn’t change, even when adjusting it in the script. Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player_movement : MonoBehaviour
{
public float speed_ = 0.1f;
// Start is called before the first frame update
void Start()
{
transform.position = new Vector3(0f, 0f, 0f);
}
public Transform player;
// Update is called once per frame
void Update()
{
if (Input.GetKey("w"))
{
if (player.position.y <= 3.5f) //if player y is less than/equal to 3.5
{
transform.Translate(0f, 0.2f, 0f * speed_); //go up by 0.2
}
}
if (Input.GetKey("s"))
{
if (player.position.y >= -4.0f) //if player y is greater than/equal to -4
{
transform.Translate(0f, -0.2f, 0f * speed_); //go down by 0.2
}
}
if (Input.GetKey("a"))
{
if (player.position.x >= -0.5f)
{
transform.Translate(-0.2f, 0f, 0f * speed_);
}
}
if (Input.GetKey("d"))
{
transform.Translate(0.2f, 0f, 0f * speed_);
}
}
}
and here’s a video demonstration