停止降低玩家在相反方向移动时的距离值?

问题描述:

我有一个玩家在碰到平台时跳跃。有点像涂鸦跳。得分基于在y轴上行进的距离。问题是,当玩家跳起来时,距离值(分数)增加,但是当玩家返回平台时,距离值减小,因此分数也减小。我想阻止分数下降。这里的脚本:停止降低玩家在相反方向移动时的距离值?

public GameObject player; 
float beginPos; 
float curPos; 
public int Multiplier; 

void Start() { 
    beginPos = player.transform.position.y; 
} 

void Update() { 
    curPos = player.transform.position.y - beginPos; 
    int Distance = Mathf.RoundToInt(curPos * Multiplier); 
    Debug.log(Distance); 
} 
+0

猜你可以添加一个属性给玩家,表明他是否跳跃,如果是的话,不扣分? – MushyPeas

+0

听起来像你可能想要一个像apex这样的附加变量,并围绕它构建计算。 – Yepher

+0

玩家不断跳跃!没有运动。他触摸平台并沿+ y方向跳跃。他错过了这个平台,游戏结束了。任何其他想法?我试着制作另一个变量,maxDist,它可以存储距离并将其与之前的值进行比较,但我无法使其工作。 –

设定的最高高度只有更新的分数,如果你去过去达成的最大高度。

float beginPos; 
float curPos; 
public int Multiplier; 
float maxHeight; 
void Start() { 
    beginPos = player.transform.position.y; 
    maxHeight = beginPos; 
} 
void Update() { 

    curPos = player.transform.position.y - beginPos; 

    if(curPos > maxHeight) 
    { 
     int Distance = Mathf.RoundToInt(curPos* Multiplier); 
     maxHeight = curPos; 
     Debug.log(Distance); 
    } 
} 
+0

随着玩家不断向上移动,无法设置maxHeight!它的位置不断变化。 –

+0

我想你误会了。在这种情况下,maxHeight只是记住了玩家所达到的最高点。如果当前玩家位置超过maxHeight,那么你知道他比以前更高,所以分数更新并且将maxHeight设置为当前位置。 – Equalsk

+1

工作!成功了!非常感谢!使用另一个变量是要走的路。再次感谢你!!!! –

void Update() { 
    curPos = player.transform.position.y - beginPos; 
    if (curPos > 0) { 
     distance = Mathf.RoundToInt(curPos * Multiplier); 
    } 
} 
+0

不起作用。该值仍然下降。参考玩家不停留在(0,0,0)。他不断向上移动。 –