using UnityEngine;
public class movment : MonoBehaviour{
bool canJump;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("a"))
{
gameObject.transform.Translate(-1f * Time.deltaTime, 0, 0);
}
if (Input.GetKey("d"))
{
gameObject.transform.Translate(1f * Time.deltaTime, 0, 0);
}
}
ManageJump();
}
void ManageJump()
{
if(gameObject.transform.position.y <= 0)
{
canJump = true;
}
if(Input.GetKey("space") && canJump && gameObject.transform.position.y < 10)
{
gameObject.transform.Translate(0, 50f * Time.deltaTime, 0);
}
else
{
canJump = false;
if(gameObject.transform.position.y > 0)
{
gameObject.transform.Translate(0, -50f * Time.deltaTime, 0);
}
}
}
↧