繁体   English   中英

如何创建分数乘数?

[英]How to create a score multiplier?

我正在制作一个无休止的滑雪游戏,并且已经有一个评分系统,但是我想根据在不接触地面的情况下完成的连续技巧的数量添加一个分数乘数。 到目前为止,这是我的脚本:

public class tricksScore : MonoBehaviour
{
    private float flips = 0;
    private float deltaRotation = 0;
    private float currentRotation = 0;
    private float WindupRotation = 0;
    public static Rigidbody2D rigbod;
    public Text scores;
    private int trickscore;
    private int iflip;
    private int oldscore;
    private int incInScore;
    public float speed;
    private float counter;
    private int flipscore;
    private int rockDestroy;
    private bool grounded;
    private int multiplier = 1;
    // Collision2D coll;

    // Start is called before the first frame update
    void Start()
    {
        speed = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().speed;
        scores = GameObject.Find("score").GetComponent<Text>();
        rigbod = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>();
        grounded = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().grounded;
    }

    // Update is called once per frame
    void Update()
    {
        rigbod.velocity = new Vector2(speed, rigbod.velocity.y);
        deltaRotation = currentRotation - rigbod.transform.eulerAngles.z;
        currentRotation = rigbod.transform.eulerAngles.z;
        if (deltaRotation >= 300) deltaRotation -= 360;
        if (deltaRotation <= -300) deltaRotation += 360;
        WindupRotation += (deltaRotation);
        flips = WindupRotation / 340;
        iflip = (int)flips;
        iflip = iflip * -1;
        flipscore = iflip * 10;
        trickscore = flipscore + rockDestroy;
        scores.text = "score " + (trickscore * multiplier);
        incInScore = trickscore - oldscore;
        if (incInScore >= 10)
        {
            oldscore = trickscore;
        }
        
        //speed += (Mathf.Round(incInScore)) / 100.0f;
      
        if (incInScore > 1 && incInScore <= 10)
        {
            speed = speed + 0.15f;
            counter += 3f;
        }
        if (incInScore > 10 && incInScore <= 20)
        {
            speed = speed + 0.25f;
            counter += 3f;
        }
        if (incInScore > 20 && incInScore <= 50)
        {
            speed = speed + 0.50f;
            counter += 3f;
        }
        if (incInScore > 50 && incInScore <= 100)
        {
            speed = speed + 0.75f;
            counter += 3f;
        }
        if (incInScore > 100 && incInScore <= 200)
        {
            speed = speed + 1f;
            counter += 3.5f;
        }
        if (incInScore > 200)
        {
            speed = speed + 2f;
            counter += 4f;
        }

        if (incInScore > 5 && grounded == false)
        {
            multiplier = multiplier + 1;
        } 
        else if (grounded == true)
        {
            multiplier = 1;
        }

        if (speed > 5.15f)
        {
            speed -= 0.05f * Time.deltaTime;
        } 
        else if (speed == 5.15f)
        {
            speed = 5.15f;
        }
         
        counter -= 1.0f * Time.deltaTime;
 
        if (counter < 0)
        {
            counter = 0;
        }

        if (incInScore >= 10)
        {
            incInScore = 0;             
        }

        if (incInScore < 0)
        {
            incInScore = incInScore * -1;
        }
    }

    private void OnCollisionEnter2D(Collision2D coll)
    {
        //counter = GameObject.FindGameObjectWithTag("Player").GetComponent<tricksScore>().counter;
        if (counter > 0)
        {
            if (coll.collider.tag == "rock")
            {
                Destroy(coll.gameObject);
                speed = speed + 0.15f;
                rockDestroy = rockDestroy + 5;
                counter = counter + 2f;
            }            
        }
    }
}

我知道脚本很脏,但希望它对你们所有人来说仍然可以理解。 在此先感谢您的帮助。

您的接地 boolean 仅设置在 start 中,因此几乎总是错误的。 在更新function中加入check语句,因为当你用这个属性设置一个变量时,它只会取当时的值,不会自动更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM