C# 如何创建分数乘数?

C# 如何创建分数乘数?,c#,unity3d,C#,Unity3d,我正在进行一场无休止的滑雪比赛,并且已经有了一个计分系统,但是我想根据在不触地的情况下连续完成的动作数增加一个计分乘数。以下是我目前的脚本: public class tricksScore : MonoBehaviour { private float flips = 0; private float deltaRotation = 0; private float currentRotation = 0; private float WindupRotatio

我正在进行一场无休止的滑雪比赛,并且已经有了一个计分系统,但是我想根据在不触地的情况下连续完成的动作数增加一个计分乘数。以下是我目前的脚本:

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;
            }            
        }
    }
}
public class trickscore:monobhavior
{
私有浮动翻转=0;
专用浮点数旋转=0;
专用浮点电流旋转=0;
私有浮动WindUplotion=0;
公共静态刚体2d刚体bod;
公共文本分数;
私人智力测验;
私人国际图联;
私人积分;
私人住宅;
公众浮标速度;
私人浮动计数器;
私人智力测验分数;
私营企业;
私人学校;
私有整数乘数=1;
//碰撞2D coll;
//在第一帧更新之前调用Start
void Start()
{
speed=GameObject.FindGameObjectWithTag(“玩家”).GetComponent().speed;
分数=游戏对象。查找(“分数”).GetComponent();
rigbod=GameObject.FindGameObjectWithTag(“玩家”).GetComponent();
grounded=GameObject.FindGameObjectWithTag(“玩家”).GetComponent().grounded;
}
//每帧调用一次更新
无效更新()
{
rigbod.velocity=新矢量2(速度,rigbod.velocity.y);
deltaRotation=currentRotation-rigbod.transform.eulerAngles.z;
currentRotation=rigbod.transform.eulerAngles.z;
如果(三角旋转>=300)三角旋转-=360;
如果(三角旋转=10)
{
oldscore=trickscore;
}
//速度+=(数学圆(中心))/100.0f;
如果(内芯>1&&内芯10&&内芯20&&内芯50&&内芯100&&内芯200)
{
速度=速度+2f;
计数器+=4f;
}
如果(incInScore>5&&grounded==false)
{
乘数=乘数+1;
} 
else if(接地==真)
{
乘数=1;
}
如果(速度>5.15f)
{
速度-=0.05f*时间增量;
} 
否则如果(速度==5.15f)
{
速度=5.15f;
}
计数器-=1.0f*Time.deltaTime;
如果(计数器<0)
{
计数器=0;
}
如果(incenscore>=10)
{
incInScore=0;
}
如果(incenscore<0)
{
incInScore=incInScore*-1;
}
}
专用空心OnCollisionInter2D(Collision2D coll)
{
//counter=GameObject.FindGameObjectWithTag(“Player”).GetComponent().counter;
如果(计数器>0)
{
如果(coll.collider.tag==“岩石”)
{
销毁(游戏对象集合);
速度=速度+0.15f;
岩石破坏=岩石破坏+5;
计数器=计数器+2f;
}            
}
}
}

我知道剧本很脏,但希望大家都能理解。提前感谢您的帮助。

您的ground boolean仅在start中设置,因此它几乎总是false。在update函数中添加check语句,因为当您使用此属性设置变量时,它将只接受当时的值,不会自动更新。

看起来您已经有了分数乘数。你能解释一下什么不起作用吗?我创建的乘数不起作用。“计数器”在这里就像是一个增强的东西,我不认为它会影响multplierrooked的工作,而saw ground只是在开始时设置的。你必须添加
ground=GameObject.FindGameObjectWithTag(“Player”).GetComponent().grounded编码到更新函数中。当您在开始时指定“固定”时,它不会随播放器控件而更改(基本上,它在脚本开始时接受值,并且不会更改)。我猜你的角色是从地面开始的,这将导致
grounded=false,它永远不会运行乘数。如果你把它放在更新功能中,它会重新设计/更新每一帧。你修复了我的问题50%。现在分数在增加,但不是2次倒扣变成40分,而是尝试记录乘数和iflip值。我最好的猜测是乘数的增加不正确。每次更新后,请尝试将
incInScore
设置为0(如果这不会破坏您的代码)。