轮转图的几个要点:拖拽旋转、惯性缓动、对齐
拖拽矢量根据鼠标位移可以得到,从而得到旋转方向。
惯性缓动就是在一定时间内以一定速度(降速)旋转。
对齐根据z值最大的对齐。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scripting.APIUpdating;
public class PartOfCircle : MonoBehaviour
{
Vector3 start;
float slowtime = 0;
bool needStop = false;
float curvalue;
void Start()
{
}
void Update()
{
Vector3 lookat = transform.position - transform.parent.transform.position;
transform.LookAt(lookat+transform.position);
if (needStop)
{
slowtime += Time.deltaTime;
if (slowtime >= 0.5f)
{
needStop = false;
slowtime = 0;
}
else
{
Move(curvalue);
}
}
}
public void Move(float value)
{
transform.parent.Rotate(Vector3.up * Time.deltaTime * value);
}
private void OnMouseDown()
{
start = Input.mousePosition;
needStop = false;
}
private void OnMouseDrag()
{
Vector3 dir = start-Input.mousePosition;
curvalue = dir.x;
Move(dir.x);
}
private void OnMouseUp()
{
//追加惯性缓动、对齐
needStop = true;
}
}