Unity Level通过Application.LoadLevel重新加载

时间:2014-06-20 11:54:51

标签: c# unity3d

使用

重新加载关卡
Application.LoadLevel(0);

FixedUpdate()和输入没有任何想法?

void Awake()
{
    Debug.Log("Awake");
    Load();
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            switch (i)
            {
                case 0:
                    Grid[i, j] = cuber1[j];
                    break;
                case 1:
                    Grid[i, j] = cuber2[j];
                    break;
                case 2:
                    Grid[i, j] = cuber3[j];
                    break;
                case 3:
                    Grid[i, j] = cuber4[j];
                    break;
                case 4:
                    Grid[i, j] = cuber5[j];
                    break;
            }
            Occupied[i, j] = false;
        }
    }
    randomObjectSpawn();
    randomObjectSpawn();
}

void Start()
{

    Swiped = false;
    paused = false;
    GameOver = false;
    count = 0;
}

void Update()
{

    foreach (Touch t in Input.touches)
    {
        switch (t.phase)
        {
            case TouchPhase.Began:
                Initial = t.position;
                Swiped = false;
                break;
            case TouchPhase.Ended:
                Direction = t.position - Initial;
                if (Direction.magnitude > 100.0f)
                {
                    Direction = Direction.normalized;
                    Swiped = true;
                }
                break;
        }
        if (Swiped && count == 0)
        {

            if (Vector2.Dot(Direction, Vector2.up) > Mathf.Sqrt(0.5f))
            {
                // Up
                BroadcastMessage("swipedUp", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, -1 * Vector2.up) > Mathf.Sqrt(0.5f))
            {
                // Down
                BroadcastMessage("swipedDown", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, Vector2.right) > Mathf.Sqrt(0.5f))
            {
                // Right
                BroadcastMessage("swipedRight", SendMessageOptions.DontRequireReceiver);
            }
            else if (Vector2.Dot(Direction, -1 * Vector2.right) > Mathf.Sqrt(0.5f))
            {
                // Left
                BroadcastMessage("swipedLeft", SendMessageOptions.DontRequireReceiver);
            }
        }
    }
    if (count == 0)
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            // Up
            BroadcastMessage("swipedUp", SendMessageOptions.DontRequireReceiver);
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            // Down
            BroadcastMessage("swipedDown", SendMessageOptions.DontRequireReceiver);
        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            // Right
            BroadcastMessage("swipedRight", SendMessageOptions.DontRequireReceiver);
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            // Left
            BroadcastMessage("swipedLeft", SendMessageOptions.DontRequireReceiver);
        }
    }
}

void FixedUpdate()
{

    byte tempCount = 0;
    foreach (bool b in Occupied)
    {
        if (b)
        {
            tempCount++;
        }
    }
    if (count == 2 * tempCount)
    {
        randomObjectSpawn();
        count = 0;
    }
}

这是场景中的主脚本,每个生成的随机对象也有一个单独的脚本来执行基于滑动的方法。 Count用于查明是否每个对象都已完成执行该方法

0 个答案:

没有答案