Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity 3d列表<&燃气轮机;不适用于android,但适用于Unity Editor_C#_Android_List_Unity3d - Fatal编程技术网

C# Unity 3d列表<&燃气轮机;不适用于android,但适用于Unity Editor

C# Unity 3d列表<&燃气轮机;不适用于android,但适用于Unity Editor,c#,android,list,unity3d,C#,Android,List,Unity3d,我正在制作一个名为检查点的游戏对象列表。开始时,编辑器中将所有游戏对象设置为非活动。当玩家启动一个事件时,检查点会按顺序逐个激活。当车辆触发检查点时,下一个检查点将被激活。在Unity播放模式下,一切正常,没有任何错误或警告 但是,在Android构建中,下面的语句checkPoints[currentCheckPoint].SetActive(true)不起作用,并且它之后的所有代码都不会执行。我只是发布相关代码,因为完整的脚本有点长 public List<GameObject>

我正在制作一个名为检查点的
游戏对象
列表。开始时,编辑器中将所有
游戏对象设置为非活动。当玩家启动一个事件时,
检查点
会按顺序逐个激活。当车辆触发检查点时,下一个检查点将被激活。在Unity播放模式下,一切正常,没有任何错误或警告

但是,在Android构建中,下面的语句
checkPoints[currentCheckPoint].SetActive(true)不起作用,并且它之后的所有代码都不会执行。我只是发布相关代码,因为完整的脚本有点长

public List<GameObject> checkPoints;

static int tottalCheckPoints = 0;
int currentCheckPoint = 0;

private void Start()
{
    tottalCheckPoints = transform.childCount;
    for (int i = 0; i < tottalCheckPoints; i++)
    {
        if (transform.GetChild(i).tag == "CheckPoint" || transform.GetChild(i).tag == "FinaleCheckPoint")
        {
            checkPoints.Add(transform.GetChild(i).gameObject);
        }
    }
}

public void CheckPointTriggered()
{
    if (currentCheckPoint < tottalCheckPoints)
    {
        checkPoints[currentCheckPoint].SetActive(true); /*<------ that statement and all the statements after that doesn't get executed in android build.*/
        currentCheckPoint++;
    }
}
公共列表检查点;
静态int-totalcheckpoints=0;
int currentCheckPoint=0;
私有void Start()
{
tottalCheckPoints=transform.childCount;
for(int i=0;i检查点[CurrurnCufftoPosik]。StActValue(true);/*

这里需要考虑的一些事情。

static int tottalCheckPoints = 0; int currentCheckPoint = 0;

private void Start() {
    tottalCheckPoints = transform.childCount;
    for (int i = 0; i < tottalCheckPoints; i++)
    {
        if (transform.GetChild(i).tag == "CheckPoint" || transform.GetChild(i).tag == "FinaleCheckPoint")
        {
            checkPoints.Add(transform.GetChild(i).gameObject);
        }
    } }
static int-totalcheckpoints=0;int-currentCheckPoint=0;
私有void Start(){
tottalCheckPoints=transform.childCount;
for(int i=0;i
您正在将检查点总数设置为当前游戏对象中的子项总数。然后,仅当检查点具有标记“CheckPoint”或“FinaleCheckPoint”时,您才添加检查点

这意味着您的totalCheckPoints可能比您的检查点列表长度更大。只有当每个子项都有这两个标记中的一个时,它才会匹配

if (currentCheckPoint < tottalCheckPoints)
{
    checkPoints[currentCheckPoint].SetActive(true); /*<------ that statement and all the statements after that doesn't get executed in android build.*/
    currentCheckPoint++;
}
if(currentCheckPoint检查点[currentCheckPoint].SetActive(true);/*这在windows build中工作而在android build中不工作的原因是零,但在OnValidate中工作是我的构建失败的第一个原因。windows build是否工作?我打赌是否,我打赌的原因是“你正在OnValidate()中工作”这不应该在那里进行。它非常方便,以至于在我得知之前,我已经有几个项目因为这个原因延迟了部署。当场景在编辑器中启动时,编辑器会触发OnValidate,但在构建中不会调用OnValidate。如果有帮助,请检查并进行upvote


在某些情况下,我只是在Start()中添加了OnValidate()调用这就解决了问题

Finlay,问题解决了。Unity editor或我的计算机出现了一些问题,我不知道。我多次重新启动Unity,问题没有得到解决。我通常不会经常关闭我的计算机。因此,今天我重新启动了我的计算机并重新构建,所有的事情也开始在构建中工作。

我看到声明了de>List checkPoints
,但在您提供的代码中,我没有看到它在任何地方被初始化……先生,它确实在Start()方法中被初始化,Start()中的最后一个语句获取父对象的所有子对象,并将其存储在列表中。在编辑器中工作良好100%我可以在公开变量(List)中看到子对象在inspector中。是的,我不确定我在想什么。我很快看了看,没有看到它是一个暴露给编辑器的
public
字段。Android构建是否给出任何错误消息?在
Debug.Log
前后放置
SetActive
并告诉我们哪个显示,哪个不显示。该父级仅包含检查点作为子项没有别的。最后一个子项有FinaleCheckPoint标记,其他所有子项都有CheckPoint标记。1)是的,我得到了父项的所有子项。父项游戏对象中的所有子项都只是检查点。因此,特定部分甚至不是问题,它在Unity和android构建中100%正常工作。2)未访问或被任何其他脚本挂起。3)在unity editor中一切正常,那么如果它在unity editor中工作,为什么它在android构建中不工作?我还确保为android构建了正确的场景。