Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.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/0/unity3d/4.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# 如何在更新功能中将新分数添加到旧分数_C#_Unity3d - Fatal编程技术网

C# 如何在更新功能中将新分数添加到旧分数

C# 如何在更新功能中将新分数添加到旧分数,c#,unity3d,C#,Unity3d,如何在更新功能中将新分数添加到旧分数?在使用Mathf的更新功能中,我一直在努力将我的新分数添加到旧分数中。向前移动,但不工作 分数增加到无穷大。 我用的是bool,,而,时间有限,什么都不能用 我想加上剩余时间+当前分数 void Start() { LevelNumber = SceneManager.GetActiveScene().buildIndex; timertext.text = "00:" + secondLeft; nextTime = Time.t

如何在更新功能中将新分数添加到旧分数?在使用
Mathf的更新功能中,我一直在努力将我的新分数添加到旧分数中。向前移动
,但不工作
分数增加到无穷大。
我用的是
bool
,而
,时间有限,什么都不能用

我想加上剩余时间+当前分数

void Start()
{
    LevelNumber = SceneManager.GetActiveScene().buildIndex;

    timertext.text = "00:" + secondLeft;
    nextTime = Time.time + delay + 2;

    VictoryPanel.SetActive(false);
    GameOverPanel.SetActive(false);

    cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraManager>();
    //cam.Default();
    go = false;
    CountDownAnimimator.SetBool("countdown", true);
    currentScore = PlayerPrefs.GetFloat("score");
    //PlayerPrefs.DeleteAll();
}

void Update()
{
    scoretext.text = "Score: " + currentScore.ToString("0");
    if (timeleft <= 0)
    {
        timeleft = 0;
        cam.ChangeToEnd();
        //Time.TimeScale = 0;
        //timeisUp.gameObject.SetActive(true);
        //Restartbutton.gameObject.SetActive(true);
    }
    timertext.text = "" + Mathf.Round(timeleft);

    if (Time.time >= nextTime)
    {
        StartCoroutine(SetCollor());
        nextTime += interval;
    }
    if (timeleft > 0 && Time.time >= nextTime - 1)
    {
        if (Timer)
        {
            timeleft -= Time.deltaTime;
            go = true;
        }

        if (timeleft <= 10)
        {
            timertext.color = Red;
        }
        if (title1.GetComponent<SpriteRenderer>().color == Green)
        {
            cam.ChangeToEnd();
            Timer = false;
            timertext.color = Green;
            VictoryPanel.SetActive(true);
            LevelComplete();
            StartCoroutine(UpdateScore());
        }
        else if (timeleft <= 0 && Titles[index].GetComponent<SpriteRenderer>().color == Red)
        {
            cam.ChangeToEnd();
            timertext.color = Red;
            GameOverPanel.SetActive(true);
        }
    }

    if (Time.timeSinceLevelLoad >= delay)
    {
        CountDownAnimimator.SetBool("countdown", false);
        cam.ChangeToPlay();
    }
}

public void RestartLevel()
{
    timeisUp.gameObject.SetActive(false);
    Restartbutton.gameObject.SetActive(false);
    Time.timeScale = 1;
    timeleft = 40;
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

public void NextLevel()
{
    //timeisUp.gameObject.SetActive(false);
    //Restartbutton.gameObject.SetActive(false);
    //Time.timeScale = 1;
    timeleft = 40;
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}

public void BackToMenu()
{
    //timeisUp.gameObject.SetActive(false);
    //Restartbutton.gameObject.SetActive(false);
    //Time.timeScale = 1;
    timeleft = 40;
    SceneManager.LoadScene("Menu");
}

IEnumerator SetCollor()
{
    for (int i = 0; i < Titles.Length; i++)
    {
        while (used.Contains(index))
        {
            index = Random.Range(0, Titles.Length);
            yield return null;
        }
    }
    used.Add(index);
    Titles[index].GetComponent<SpriteRenderer>().color = Red;

}

void Finish()
{
    //GameObject.Find("Player").SendMessage("Finish");
    timertext.color = Green;
}

void LevelComplete()
{
    if (PlayerPrefs.GetInt("MaxLevel") == LevelNumber)
    {
        PlayerPrefs.SetInt("MaxLevel", PlayerPrefs.GetInt("MaxLevel") + 1);
    }

}

IEnumerator UpdateScore()
{
    Count = Mathf.MoveTowards(Count, timeleft, Time.deltaTime * 3.0f);
    currentScore = currentScore + Count;
    yield return new WaitForSeconds(0.1f);
    PlayerPrefs.SetFloat("score", currentScore);
    PlayerPrefs.Save();
}
void Start()
{
LevelNumber=SceneManager.GetActiveScene().buildIndex;
timertext.text=“00:”+secondLeft;
nextTime=Time.Time+delay+2;
VictoryPanel.SetActive(假);
GameOverPanel.SetActive(false);
cam=GameObject.FindGameObjectWithTag(“MainCamera”).GetComponent();
//cam.Default();
go=假;
倒计时Animator.SetBool(“倒计时”,true);
currentScore=PlayerPrefs.GetFloat(“分数”);
//PlayerPrefs.DeleteAll();
}
无效更新()
{
scoretext.text=“Score:+currentScore.ToString(“0”);
如果(timeleft=nextTime)
{
start例程(SetCollor());
下一个时间+=间隔;
}
如果(timeleft>0&&Time.Time>=nextTime-1)
{
中频(定时器)
{
timeleft-=Time.deltaTime;
去=真;
}

如果(timeleft)您不想在级别完成时添加剩余的评分时间吗?是,但在更新功能不工作中定义“不工作”你期望的是什么,发生的是什么?我想将剩余的时间间隔像lerp一样平滑地添加到currentscore并保存它,然后在新的关卡中每次都添加不等于时间间隔的时间间隔为什么要在更新中执行,而不仅仅是在关卡完成时