- Home /
Question by
kadiroz · Apr 28, 2014 at 02:24 AM ·
2ddistancetrackingendless runner
multiplication score with distance, infinite runner 2d
Hello everyone, i'm newbie and working on an infinite runner. now i"m looking for a solution for multiplication score with player's reached distance. not a score multiplication with time. because game has some options and player will be going backwards and multiplication parameter has to change with exact distance. how can i do that?
Comment
Best Answer
Answer by SteelArrow21 · Apr 28, 2014 at 03:13 AM
Im not 100% sure about what you're asking, but this is what I got out of it:
//C#
//Create and Empty GameObject at start
//script goes in Empty
//Name the script: Distance
using UnityEngine;
using System.Collections;
public class Distance : MonoBehaviour {
private float dis;
public Transform player; //assign variable player
void Awake(){
dis = Vector3.Distance(player.position, transform.position);
}
void Update(){
Debug.Log(dis); //Test to see if distance is working. Not required.
//Do whatever you want with variable dis
}
So in this script, the game will be constantly figuring out what the distance is from the player to the start. Even if you go backwards, it will tell you the exact distance. Hopefully.
@kadiroz, the dis
variable is a float, it's not a Vector3
.