Unity не изменит сцену с помощью любого из этих сценариев, которые я добавил в свой GameManager - PullRequest
0 голосов
/ 04 марта 2020

Я довольно новичок в Unity и C#, и не могу найти способ изменить свою сцену. Что может быть проблемой с обоими из них, поскольку они компилируются правильно с минимальными ошибками или без ошибок. Любая помощь будет удивительной, так как мой срок должен быть очень скоро. Заранее спасибо.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class gamemanager : MonoBehaviour
{
    public float CurrentBalance;

    public Text CurrentBalanceText;
    public store Store;
    public bool GameFin;

    // Start is called before the first frame update
    void Start()
    {
        CurrentBalance = 4000000.00f;

        CurrentBalanceText.text = CurrentBalance.ToString("C2");

        GameFin = false;


    }

    public void gamefinish()
    {
        if (CurrentBalance >= 400000000)
        {
            GameFin = true;
        }
        if (GameFin = true)
        {
            SceneManager.LoadScene(sceneBuildIndex: 1);
        }
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void AddToBalance(float amt)

    {
        CurrentBalance += amt;
        CurrentBalanceText.text = CurrentBalance.ToString("C2");

    }

    public bool CanBuy(float amtToSpend)
    {
        if (amtToSpend > CurrentBalance)
            return false;
        else
            return true;
    }




}

или

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class gamemanager : MonoBehaviour
{
    public float CurrentBalance;

    public Text CurrentBalanceText;
    public store Store;


    // Start is called before the first frame update
    void Start()
    {
        CurrentBalance = 4000000.00f;

        CurrentBalanceText.text = CurrentBalance.ToString("C2");

    }

    // Update is called once per frame
    void Update()
    {

    }

    public void AddToBalance(float amt)

    {
        CurrentBalance += amt;
        CurrentBalanceText.text = CurrentBalance.ToString("C2");

    }

    public bool CanBuy(float amtToSpend)
    {
        if (amtToSpend > CurrentBalance)
            return false;
        else
            return true;
    }
    public void GameComp()
    {
        if(CurrentBalance >= 500000000)
            SceneManager.LoadScene(sceneBuildIndex:1);

    }  

}

Еще раз, спасибо за ваше время.

1 Ответ

0 голосов
/ 04 марта 2020

gamefinish() функция

никогда не вызывается в вашем скрипте? поэтому он никогда не выполняется.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...