Hi, i would like to know how can i Jscript this:
If the player goes up following the y axis, the score increases.
If the player falls down, or goes down following the y axis, the score does not decrease.
This may seem obvious to you, but not to me unluckily
Everything i looked for on the internet seemed unadapt for me and so it looks like my only chance is asking here ^^
if your player’s position is higher than your players last position
increment score. or if the difference from your previous height and your current height is greater than 0, that means you’ve gone up. if its lesser than 0, you’re falling down.
also, you’d have to save your last position in the end.
using UnityEngine;
using System.Collections;
public class JumpIncrementScore : MonoBehaviour
{
[SerializeField]
int score = 0;
[SerializeField]
Vector3 _lastPosition;
// Use this for initialization
void Start () {
_lastPosition = this.transform.position;
}
// Update is called once per frame
void Update () {
if( ( this.transform.position.y - _lastPosition.y ) > 0 )
score++;
_lastPosition = this.transform.position;
}
void OnGUI( ) {
GUILayout.Label("Score : " + score);
}
}