基于Unity的吃豆人小游戏

这是去年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)
            {
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值