I have a game idea... and I need a script where I can control the speed for moving left, and control another speed for moving right. But, I also need to let my player face that direction.
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
void Update()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
Vector3 position = this.transform.position;
position.x -= .5f;
this.transform.position = position;
}
if (Input.GetKey(KeyCode.RightArrow))
{
Vector3 position = this.transform.position;
position.x += 1f;
this.transform.position = position;
}
if (Input.GetKey(KeyCode.A))
{
Vector3 position = this.transform.position;
position.x -= .5f;
this.transform.position = position;
}
if (Input.GetKey(KeyCode.D))
{
Vector3 position = this.transform.position;
position.x += 1f;
this.transform.position = position;
}
}
}
That is my code. I need make it better I guess... and to make the player face that direction.
better
. Do you want to have your code refactored? Do you want to have better conditions? Do you want to use the new input system? Does your game uses physics or is expected to collide with things? Did you check the documentation regarding flip property of sprites for your facing direction problem? \$\endgroup\$physics/ collisions
, you would want to move around with your rigidbody \$\endgroup\$