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