B站Unity学习笔记
链接:https://www.bilibili.com/video/BV12s411g7gU
animation组件用于播放动画。
变量
函数
练习:1.
public class Door : MonoBehaviour
{
public bool doorState = false;
public string animName = "Door";
private Animation anim;
private void Start()
{
anim = GetComponent<Animation>();
}
//点击当前物体时执行
private void OnMouseDown()
{
if (doorState)
{
//如果当前动画组件没有播放动画片段
if (!anim.isPlaying) anim[animName].time = anim[animName].length;
//关门 1 -->0
anim[animName].speed = -1;
}
else
{
//开门 0-->1
anim[animName].speed = 1;
}
anim.Play(animName);
doorState = !doorState;
}
}
练习2:“英雄无敌”项目敌人模块
具体参见https://blog.csdn.net/weixin_41963554/article/details/116134004