Unity2019.4.16f1c1 2d学习笔记 part2

1、The script don't inherit a native class that can manage a script.

原因是你的类名和你类的文件名不同导致,修改成相同名称即可。

2、Animation Events动画事件名称需要手动写,没有办法自动获取

事件中的函数和脚本中的函数名相同即可

系统会自动调用

 

3、The Asset Store has moved

新版的资源库被移动了,需要使用Package Manager去搜索管理

导入

4、抽象怪物类的死亡方法,减少代码的重复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script
{
    public class Enemy : MonoBehaviour
    {
        protected Animator Ani;

        protected virtual void Start()
        {
            Ani = GetComponent<Animator>();
        }

        protected virtual void Death()
        {
            Destroy(gameObject);
        }

        public void Deathing()
        {
            Ani.SetBool("runing", false);
            Ani.SetBool("death", true);
        }
    }
}

怪物青蛙

using Assets.Script;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FrogControler : Enemy
{
    private Rigidbody2D FrogRd;
    public Transform LeftPoint;
    public Transform RightPoint;
    public bool IsFaceLeft = true;
    public float Speed;

    // Start is called before the first frame update
    protected override void Start()
    {
        base.Start();
        FrogRd = GetComponent<Rigidbody2D>();
        transform.DetachChildren();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Movement();
    }

    void IdleEven()
    {
        Ani.SetBool("runing", true);
    }

    void JumpEven()
    {
        Ani.SetBool("runing", false);
    }

    void DeathEven()
    {
        Death();
    }

    void Movement()
    {
        if (Ani.GetBool("runing") == true)
        {
            if (IsFaceLeft)
            {
                FrogRd.velocity = new Vector2(-Speed * Time.deltaTime, FrogRd.velocity.y);
                if (transform.position.x < LeftPoint.position.x)
                {
                    IsFaceLeft = false;
                }
                Ani.SetBool("runing", true);
                transform.localScale = new Vector3(1, 1, 1);
            }
            else
            {
                FrogRd.velocity = new Vector2(Speed * Time.deltaTime, FrogRd.velocity.y);
                if (transform.position.x > RightPoint.position.x)
                {
                    IsFaceLeft = true;
                }
                Ani.SetBool("runing", true);
                transform.localScale = new Vector3(-1, 1, 1);
            }
        }
    }
}

怪物老鹰

using Assets.Script;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EagleControler : Enemy
{
    public Rigidbody2D EagleRb;
    public Transform UpPoint;
    public Transform DownPoint;
    public bool IsUp = true;
    public float Speed;

    protected override void Start()
    {
        base.Start();
        EagleRb = GetComponent<Rigidbody2D>();
        transform.DetachChildren();
    }

    void FixedUpdate()
    {
        Movement();
    }

    void DeathEven()
    {
        Death();
    }

    public void Movement()
    {
        if (IsUp)
        {
            EagleRb.velocity = new Vector2(EagleRb.velocity.x, Speed * Time.deltaTime);
            if (transform.position.y > UpPoint.position.y)
            {
                IsUp = false;
            }
        }
        else
        {
            EagleRb.velocity = new Vector2(EagleRb.velocity.x, -Speed * Time.deltaTime);
            if (transform.position.y < DownPoint.position.y)
            {
                IsUp = true;
            }
        }
    }
}

5、添加的音频资源只在当前场景有效

组件前面蓝色,说明只在当前场景有效

如果想添加到预制体中,需要设置这个重写,点击应用全部Apply All

6、音频没有试听按钮

按图中箭头拖拽

拖拽后即可播放

7、2个常用音乐

casual game

Retro Sound Effects

8、Visual Studio批量重命名

Ctrl+R+R,选择好要修改的变量名,按下Ctrl按一下R抬起在按下R 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花开花落的个人博客

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值