簡體   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