- Home /
Question by
randomlyaddme · Mar 25 at 03:28 PM ·
movementship
why this my player not moving. I am making a shmup game,why is my player not working. i am making a shmup game
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class movement : MonoBehaviour { public float speed = 5f; bool moveUp; bool moveDown; bool moveLeft; bool moveRight;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
moveUp = Input.GetKey(KeyCode.W) &l Input.GetKey(KeyCode.UpArrow);
moveDown = Input.GetKey(KeyCode.S) & Input.GetKey(KeyCode.DownArrow);
moveLeft = Input.GetKey(KeyCode.A) & Input.GetKey(KeyCode.LeftArrow);
moveRight = Input.GetKey(KeyCode.D) & Input.GetKey(KeyCode.RightArrow);
}
private void FixedUpdate()
{
Vector2 pos = transform.position;
float moveAmount = speed * Time.fixedDeltaTime;
Vector2 move = Vector2.zero;
if(moveUp)
{
move.y += moveAmount;
}
if(moveDown)
{
move.y -= moveAmount;
}
if(moveLeft)
{
move.x -= moveAmount;
}
if(moveRight)
{
move.x += moveAmount;
}
transform.position = pos;
}
},
Comment