这是去年9月份写的一个小游戏,素材是网上找的,最开始跟着网上教程做了一遍,后来源文件找不到了,就用素材自己写了一遍,实现了控制玩家移动,拾取豆子,敌人移动,敌人加速移动,玩家拾取道具加速,游戏输赢判定等功能,一共有5个类,下面详细展示一下:
玩家移动类:
public class Player_move : MonoBehaviour
{
public float speed = 0.1f;
public AnimationClip[] player_anima;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
if (Input.GetKey(KeyCode.D))
{
if(GetComponent<Animator>().GetInteger("state") != 0)
{
GetComponent<Animator>().SetInteger("state", 0);
}
transform.Translate(Vector2.right * speed, Space.Self);
//GetComponent<Animation>(). = player_anima[0];
}
if (Input.GetKey(KeyCode.W))
{
if (GetComponent<Animator>().GetInteger("state") != 1)
{
GetComponent<Animator>().SetInteger("state", 1);
}
transform.Translate(Vector2.up * speed, Space.Self);
//GetComponent<Animation>().clip = player_anima[1];
}
if (Input.GetKey(KeyCode.A))
{
if (GetComponent<Animator>().GetInteger("state") != 2)
{