【问题标题】:application.loadlevel not workingapplication.loadlevel 不工作
【发布时间】:2018-02-19 20:59:50
【问题描述】:

我在 if 语句中使用 Application.LoadLevel 时遇到问题

代码如下:

using UnityEngine;
using System.Collections;

public class Ritch: MonoBehaviour {


public bool dragging = false;

void Update () {

    if (PreRitch.Deathritch == true)
    {

        transform.position = new Vector3(8f,6.89f,9f);

    }

    if (transform.position.x > 11.5 && dragging == false)
    {

        Application.LoadLevel(0);

    }

    else if (transform.position.x < 4.5 && dragging == false)
    {

        Application.LoadLevel(0);

    }



}

void OnMouseDown()
{

    dragging = true;

}

void OnMouseUp()
{

    dragging = false;

}
}

程序没有加载所需的级别,如果我在其中一个 if 语句中放置了一条打印语句,则不会打印任何内容。

【问题讨论】:

  • 可能你的if 语句表达式是假的?
  • 我放了一个打印声明,结果是真的
  • 你说if I put a print statement inside of one of the if statements nothing is printed.
  • 我把 print 语句放在 void update 而不是 if 语句中
  • 您必须确保您的布尔表达式可以变为真,并且您已将关卡添加到构建设置中

标签: c# unity3d game-development


【解决方案1】:

尝试将代码更改为:

using UnityEngine;
using System.Collections;

public class Ritch: MonoBehaviour {


public bool dragging = false;

void Update () {

    if (PreRitch.Deathritch == true)
    {

        transform.position = new Vector3(8f,6.89f,9f);

    }

    //if (transform.position.x > 11.5 && dragging == false)
    if (transform.position.x > 11.5f && dragging == false)
    {
        //Application.LoadLevel(0);
        UnityEngine.SceneManagement.SceneManager.LoadScene(0);

    }
    //else if (transform.position.x < 4.5 && dragging == false)
    else if (transform.position.x < 4.5f && dragging == false)
    {
        //Application.LoadLevel(0);
        UnityEngine.SceneManagement.SceneManager.LoadScene(0);

    }



}

void OnMouseDown()
{

    dragging = true;

}

void OnMouseUp()
{

    dragging = false;

}
}

您可以通过添加 f 或 F char 来使用浮点数而不是双精度数

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-19
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 2013-03-05
    相关资源
    最近更新 更多