NG_/Assets/Scripts/UI/工具栏/AutoRotate.cs

30 lines
931 B
C#
Raw Normal View History

2024-12-13 19:40:05 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
// 自动旋转
public class AutoRotate : MonoBehaviour,IPointerClickHandler
{
public GameObject rotateObject; // 旋转对象
public List<Sprite> sprites; // 0 旋转图片 1 停止图片
private bool isRotate; // 是否旋转
public void OnPointerClick(PointerEventData eventData)
{
// 获取椭圆运动组件
EllipticalMovement ellipticalMovement = rotateObject.GetComponent<EllipticalMovement>();
// 目前运动状态
isRotate = ellipticalMovement.isRun;
// 改变运动状态
isRotate = !isRotate;
ellipticalMovement.isRun =isRotate;
StartCoroutine(ellipticalMovement.RotateAndPause());
// 改变图片
this.GetComponent<Image>().sprite = sprites[isRotate?1:0];
}
}