application.loadlevel无法正常工作

时间:2018-02-19 20:59:50

标签: c# unity3d game-development

我在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语句中放入一个print语句,则不打印任何内容。

1 个答案:

答案 0 :(得分:0)

尝试将代码更改为:

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

来使用浮点数而不是双精度数