我这里使用了DoTween插件
下载 请在Unity 的Asset Store里下载
实例代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class TuBiao : MonoBehaviour
{
//创建一个变量 用来改变小图标 是上 还是下 的动画
public int index = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//当index=1 是往上移动
if (index == 1)
{
transform.DOMove(transform.position + new Vector3(0, 0.5f, 0), 0.5f);
Invoke("MoveTuBiao2", 1);
}
else { //否则 向下移动
transform.DOMove(transform.position - new Vector3(0, 0.5f, 0), 0.5f);
Invoke("MoveTuBiao1", 1);
}
}
private void MoveTuBiao1() {
index = 1;
}
private void MoveTuBiao2()
{
index = 2;
}
}
将上面的代码 直接挂载到 要实现上下跳动动画 的物体上 即可实现