using UnityEngine;
using System.Collections;
public class OpenButton : MonoBehaviour {
public GameObject sliders;
bool a = true;
public void OnClick()
{
a = !a;
if (a)
{
sliders.SetActive(false);
}
else
{
sliders.SetActive(true);
}
}
}
再次点击之后
第二种方法:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SwitchCamera : MonoBehaviour
{
public GameObject MainCameras;
public GameObject tracks;
public GameObject carts;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
MainCameras.SetActive(!MainCameras.activeSelf);
tracks.SetActive(!tracks.activeSelf);
carts.SetActive(!carts.activeSelf);
}
}
}