Unity3d 时间分数乘数

Unity3d 时间分数乘数,unity3d,time,multiplication,unity5,seconds,Unity3d,Time,Multiplication,Unity5,Seconds,这是我制作的分数管理器脚本: using UnityEngine; using System.Collections; using UnityEngine.UI; public class ScoreManager : MonoBehaviour { public Text scoreText; public float scoreCount; // What the score is when the scene first loads. I set this

这是我制作的分数管理器脚本:

using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;

 public class ScoreManager : MonoBehaviour {

     public Text scoreText;

     public float scoreCount; // What the score is when the scene first loads. I set this as zero.

     public float pointsPerSecond; // Every second, the points increase by THIS amount. Right now it is 100.

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

         scoreCount += pointsPerSecond * Time.deltaTime;

         scoreText.text = "" + Mathf.Round (scoreCount); // It comes out as a float with like 6 decimals; I round to an nice, clean Integer 

     }
 }

我无法解决的问题是:如何制作一个乘数,在30秒后将分数乘以2,然后在1分钟后将分数乘以3,然后在1分30秒后乘以4,最后在2分钟后乘以5?谢谢:)

这是使用
IEnmurator
功能的绝佳机会。这些是您可以调用的方法,您可以告诉它们在恢复之前等待一段时间。所以在你的例子中,你可以有一个
IEnumerator
函数,每30秒乘以你的分数。例如:

public Text scoreText;

public float scoreCount; // What the score is when the scene first loads. I set this as zero.

public float pointsPerSecond; // Every second, the points increase by THIS amount. Right now it is 100.

private int scoreMultiplier = 1;

void Start()
{
    StartCoroutine(MultiplyScore());
}

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

     scoreCount += pointsPerSecond * Time.deltaTime;

     scoreText.text = "" + Mathf.Round (scoreCount); // It comes out as a float with like 6 decimals; I round to an nice, clean Integer 

 }

IEnumerator MultiplyScore()
{
    while(true)
    {
        yield return new WaitForSeconds(30);
        scoreMultiplier++;
        scoreCount *= scoreMultiplier;
    }
}
注意,如果您只想将乘法增加到5倍,则可以使用score乘数变量作为
IEnumerator
中的条件,同时循环如下:

IEnumerator MultiplyScore()
{
    while(scoreMultiplier < 5)
    {
        yield return new WaitForSeconds(30);
        scoreMultiplier++;
        scoreCount *= scoreMultiplier;
    }
}
IEnumerator multilyscore()
{
而(分数乘数<5)
{
返回新的等待秒(30);
分数乘法器++;
scoreCount*=分数乘数;
}
}

这是使用
IEnmurator
功能的绝佳机会。这些是您可以调用的方法,您可以告诉它们在恢复之前等待一段时间。所以在你的例子中,你可以有一个
IEnumerator
函数,每30秒乘以你的分数。例如:

public Text scoreText;

public float scoreCount; // What the score is when the scene first loads. I set this as zero.

public float pointsPerSecond; // Every second, the points increase by THIS amount. Right now it is 100.

private int scoreMultiplier = 1;

void Start()
{
    StartCoroutine(MultiplyScore());
}

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

     scoreCount += pointsPerSecond * Time.deltaTime;

     scoreText.text = "" + Mathf.Round (scoreCount); // It comes out as a float with like 6 decimals; I round to an nice, clean Integer 

 }

IEnumerator MultiplyScore()
{
    while(true)
    {
        yield return new WaitForSeconds(30);
        scoreMultiplier++;
        scoreCount *= scoreMultiplier;
    }
}
注意,如果您只想将乘法增加到5倍,则可以使用score乘数变量作为
IEnumerator
中的条件,同时循环如下:

IEnumerator MultiplyScore()
{
    while(scoreMultiplier < 5)
    {
        yield return new WaitForSeconds(30);
        scoreMultiplier++;
        scoreCount *= scoreMultiplier;
    }
}
IEnumerator multilyscore()
{
而(分数乘数<5)
{
返回新的等待秒(30);
分数乘法器++;
scoreCount*=分数乘数;
}
}
InvokeRepeating设置第一个调用(第二个参数)和频率(第三个参数),在您的情况下是30秒,也是30秒。然后,一旦乘数太大(大于5),就取消调用

如果乘数是整数,则可以删除边距并使用整数

InvokeRepeating设置第一个调用(第二个参数)和频率(第三个参数),在您的情况下是30秒,也是30秒。然后,一旦乘数太大(大于5),就取消调用

如果乘数是整数,则可以删除边距并使用整数