This question was
closed Oct 11, 2016 at 09:41 PM by
StylishPillow for the following reason:
The question is answered, right answer was accepted
Question by
StylishPillow · Oct 11, 2016 at 10:47 AM ·
gameobject
Score based on player.y position?
So I am making a doodle jump clone for school and I got stuck on the scoring part. I thought of something like this player.score = player.transform.y But I now have no idea how to make it work, Help a novice out?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerScore : MonoBehaviour {
public int score;
public GameObject player;
public GUIText text;
void Start()
{
score = 0;
}
void Addscore()
{
}
void UpdateScore()
{
text.text = "Score: " + score;
}
}
Comment
If the score should be based on the highest y position reached, then do it like this:
void Update() {
int y_floor = $$anonymous$$athf.FloorToInt(transform.position.y;
if(y_floor > score) {
score = y_floor;
}
}
So I did what you said and it worked, but the score stays 0. Is that because the floor isnt anything in my game?
int y_floor = $$anonymous$$athf.FloorToInt(player.transform.position.y);