需要显示回弹功能的直接挂上就行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 做不定圆周回弹运动
/// </summary>
public class CircleAni : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
ChangeVct();
}
// Update is called once per frame
float rotateSpeed = 1;
//可以在外部inspector上勾选以方便多个旋转时方向不同步
public bool isRotate_S = false;
float timeNum = 5;
float upNum = 0;
void Update()
{
upNum += Time.deltaTime;
if (upNum> timeNum)
{
upNum = 0;
ChangeVct();
isRotate_S = !isRotate_S;
}
var speed = (isRotate_S ? -rotateSpeed : rotateSpeed)*(0.5f+Mathf.Abs(0.5f- upNum/timeNum));
var num = transform.localEulerAngles.z+ speed;
transform.localRotation = Quaternion.Euler(0,0,num);
}
//不固定的时间回弹
void ChangeVct()
{
//给个4-10秒的取值范围
timeNum = 4 + Random.Range(0, 6);
rotateSpeed = 0.4f + 0.5f * Random.Range(0, 1);
}
}