30 lines
931 B
C#
30 lines
931 B
C#
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];
|
|
}
|
|
}
|