保存分数在检查点

huangapple go评论50阅读模式
英文:

Saving score at checkpoint

问题

我正在制作一个3D BMX侧滚游戏,其中包含技巧系统和得分。我已经在游戏中添加了检查点,当你摔倒时它们运作良好。我遇到的问题是,当你摔倒时,得分不会回到你首次通过检查点时的得分,这意味着人们可以通过执行一个非常大的技巧然后一遍又一遍地摔倒来获得高分。每个教程,我是指真的每一个,都是关于在关卡结束时保存高分。以下是相关的脚本:

private float flipScore;
private float spinScore;

void FixedUpdate()
{
    if (!IsGrounded())
    {
        flipScore += (transform.localEulerAngles.x) * Time.deltaTime * 0.5f;
        spinScore += transform.localEulerAngles.y * Time.deltaTime * 1f;
    }
}

为了提供额外的说明,这是一个示例:当你到达第一个检查点时,得分为12345分。你执行一些技巧,将得分提高到15000分,但在下一个检查点之前摔倒,然后你重新回到第一个检查点,得分为12345分。

我已经尝试了几乎所有我在教程中看到的方法,但都没有成功。

英文:

I'm working on a 3D BMX sidescroller with a trick system and points. I've all ready got check points in for when you crash and they work well. The problem I'm having is when you crash your score doesn't go back to what it was when you first passed the checkpoint, meaning people can just get a high score by doing a really big trick and crashing over and over again. Every tutorial, and I mean literally every one, has been about saving a high score at the end of a level. Here's the relevant script

private float flipScore;
private float spinScore;

void FixedUpdate()

if (!IsGrounded())
        
            flipScore += (transform.localEulerAngles.x) * Time.deltaTime * 0.5f;
            spinScore += transform.localEulerAngles.y * Time.deltaTime * 1f;

An example for anyone who needs extra clarification.
You reach the first checkpoint with 12345 points. You do a few tricks to get up to 15000 but crash before the next checkpoint then you start back at the first checkpoint with 12345 points.

I've tried pretty much everything I've seen in the tutorials but to no avail.

答案1

得分: 1

在达到检查点时存储分数。
在重置到检查点时,将分数设置为已存储的值。

private float checkpointSpinScore;
private float checkpointFlipScore;

private void OnCheckpointReached()
{
checkpointSpinScore = spinScore;
checkpointFlipScore = flipScore;
}
private void OnResetToCheckpoint()
{
spinScore = checkpointSpinScore;
flipScore = checkpointFlipScore;
}

英文:

Store the points when you reach a checkpoint.
When resetting to the checkpoint, set the score to what was stored.

private float checkpointSpinScore;
private float checkpointFlipScore;

private void OnCheckpointReached()
{
    checkpointSpinScore = spinScore;
    checkpointFlipScore = flipScore;
}
private void OnResetToCheckpoint()
{
    spinScore = checkpointSpinScore;
    flipScore = checkpointFlipScore;
}

huangapple
  • 本文由 发表于 2023年2月16日 06:44:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定