我有两个脚本 button.cs 附加到“开始”按钮对象并带有标志 var。并将 Restart.cs 附加到 RestartButton 对象。我正在尝试从 Restart.cs 中的 Button.cs 更改布尔标志。我得到这个错误:
Assets\Scripts\Restart.cs(14,63): error CS0122: 'Button.flag' is inaccessible due to its protection level
这是button.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Button : MonoBehaviour
{
// Start is called before the first frame update
public GameObject m_cube, obeme, resetButton;
public AudioSource audioSource;
public bool flag = false;
void OnMouseDown(){
if (!flag)
{
flag = true;
transform.localRotation = Quaternion.Euler(0, 0, 180);
m_cube.GetComponent <Animation> ().Play ("cubeGoDown2");
audioSource.Play();
obeme.GetComponent <Animation> ().Play ("obemeGetIn");
resetButton.GetComponent <Animation> ().Play ("RestartButtonGetIn");
}
}
}
这是Restart.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Restart : MonoBehaviour
{
// Start is called before the first frame update
public GameObject resetButton;
void OnMouseDown()
{
transform.localRotation = Quaternion.Euler(0, 0,0);
GameObject.Find("Start button").GetComponent<Button>().flag = false;;
resetButton.GetComponent <Animation> ().Play ("RestartButtonGetOut");
}
}