Hey everyone,
I am here to ask for help on a script that I am trying to write.
It will calculate the positions of the player and the AI and put it on a text object to display it.
Although I don’t quite know how I will do this, I have the distance to the next waypoint, what lap the AI and player are on and what waypoint they had passed.
Any help on how to continue this would be amazingly appreciated.
As you can see so far I am getting all the information that I think I will need such as distance to the next waypoint but I just cannot think of how to carry it on. At first I started writing if statements but I figured it would take tens of them so there must be an easier way.
using UnityEngine;
using System.Collections;
public class RacePositions : MonoBehaviour {
private int PlayerOnePosition;
private int AiOnePosition;
private int AiTwoPosition;
private int AiThreePosition;
private float PlayerOneDistance;
private float AiOneDistance;
private float AiTwoDistance;
private float AiThreeDistance;
private int PlayerOneWaypoints;
private int AiOneWaypoints;
private int AiTwoWaypoints;
private int AiThreeWaypoints;
private int PlayerOneLaps;
private int AiOneLaps;
private int AiTwoLaps;
private int AiThreeLaps;
private GameObject PlayerOneTarget;
private Transform AiOneTarget;
private Transform AiTwoTarget;
private Transform AiThreeTarget;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Debug.Log ("P1: " + PlayerOneDistance + "AI 1: " + AiOneDistance + "AI 2: " + AiTwoDistance + "AI 3: " + AiThreeDistance);
PlayerOneTarget = GameObject.FindWithTag ("Waypoint " + GameObject.Find ("Player One").GetComponent<LapCounter3D> ().WaypointsPassed);
AiOneTarget = GameObject.Find ("AI 1").GetComponent<UnityStandardAssets.Vehicles.Car.CarAIControl> ().m_Target;
AiTwoTarget = GameObject.Find ("AI 2").GetComponent<UnityStandardAssets.Vehicles.Car.CarAIControl> ().m_Target;
AiThreeTarget = GameObject.Find ("AI 3").GetComponent<UnityStandardAssets.Vehicles.Car.CarAIControl> ().m_Target;
PlayerOneWaypoints = GameObject.Find ("Player One").GetComponent<LapCounter3D> ().WaypointsPassed;
AiOneWaypoints = GameObject.Find ("AI 1").GetComponent<LapCounter3D> ().WaypointsPassed;
AiTwoWaypoints = GameObject.Find ("AI 2").GetComponent<LapCounter3D> ().WaypointsPassed;
AiThreeWaypoints = GameObject.Find ("AI 3").GetComponent<LapCounter3D> ().WaypointsPassed;
PlayerOneLaps = GameObject.Find ("Player One").GetComponent<LapCounter3D> ().LapCount;
AiOneLaps = GameObject.Find ("AI 1").GetComponent<LapCounter3D> ().LapCount;
AiTwoLaps = GameObject.Find ("AI 2").GetComponent<LapCounter3D> ().LapCount;
AiThreeLaps = GameObject.Find ("AI 3").GetComponent<LapCounter3D> ().LapCount;
//Calculate the distance between me and the target which
//would be the next waypoint.
PlayerOneDistance = Vector3.Distance (GameObject.Find("Player One").transform.position, PlayerOneTarget.transform.position);
AiOneDistance = Vector3.Distance (GameObject.Find ("AI 1").transform.position, AiOneTarget.transform.position);
AiTwoDistance = Vector3.Distance (GameObject.Find ("AI 2").transform.position, AiTwoTarget.transform.position);
AiThreeDistance = Vector3.Distance (GameObject.Find ("AI 3").transform.position, AiThreeTarget.transform.position);
}
}
Thanks.
EDIT:
This goes on my _RaceManager gameobject.