【发布时间】:2021-12-27 11:39:28
【问题描述】:
为什么我的布尔值设置只执行一次?然后返回false?当我执行它的功能时,设置为“true”一次,然后返回false。
private bool[] set = new[] { false, false, false, false};
void Update()
{
movefunc(setSpineRotates[0], "spinerotatecolor");
}
void movefunc(bool set, string co)
{
if (Input.touchCount == 1)
{
Touch screentouch = Input.GetTouch(0);
Ray ray = camera.ScreenPointToRay(screentouch.position);
if (screentouch.phase == TouchPhase.Began)
{
if (Physics.Raycast(ray, out RaycastHit hitInfo))
{
if (hitInfo.collider.gameObject.GetComponent(co) != null)
{
set = true;
}
}
}
}
Debug.log(set);
//. when i perform the function it, set to "true" once,then return to false.
if (set)
{
sliderx.SetActive(true);
slidery.SetActive(true);
sliderz.SetActive(true);
}
}
所以当我执行函数时,它是否只复制值?
【问题讨论】:
-
为什么
set = true;甚至编译¿? ->Cannot implicilty convert type bool to bool[] -
@rustyBucketBay no 在 OP 的方法中还有参数
bool set隐藏了外部bool[] set.. -
哦,非常正确。谢谢
-
请使用正确的标签!请注意,
unityscript是或更好的是曾经是一种 JavaScript 风格,类似于早期 Unity 版本中使用的自定义语言,并且现在已经不推荐使用了!你的代码在c#..