You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
881 B

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum SwitchState {
on,
off
}
public class Switch : MonoBehaviour
{
SwitchState curState;
public Sprite on;
public Sprite off;
public Image image;
Vector3 birthpos;
public Vector3 targetpos;
public GameObject qiu;
private void Awake()
{
birthpos = qiu.transform.localPosition;
curState = SwitchState.off;
}
public void updateShow() {
print("点击");
if (curState == SwitchState.on)
{
curState = SwitchState.off;
image.sprite = off;
qiu.transform.localPosition = birthpos;
}
else {
curState = SwitchState.on;
image.sprite = on;
qiu.transform.localPosition = targetpos;
}
}
}