void Start() { GameObject tmpObj = GameObject.Find("P" + transform.GetComponent <CarController> ().playerNumber + "_Target"); // you need to have a gameObject named "P1_Target" "P2_Target" "P3_Target" "P4_Target" on your scene if (tmpObj) { target = tmpObj.transform; // access the target that follow the car } tmpObj = GameObject.Find("Track_Path"); if (tmpObj) { Track = tmpObj.GetComponent <UnityStandardAssets.Utility.WaypointCircuit>(); // access the track (car path) } if (Track != null && Track.waypointList.items.Length > 0) { pathExist = true; } tmpObj = GameObject.Find("StartLine_lapCounter"); if (tmpObj) { sLapCounter = tmpObj.GetComponent <LapCounter> (); // access the track (car path) } carPathFollow = GetComponent <CarPathFollow> (); }
public WaypointTracker(Transform carTransform, UnityStandardAssets.Utility.WaypointCircuit circuit, Transform target = null) { transform = carTransform; this.circuit = circuit; float minDistance = Vector3.Distance(transform.position, circuit.Waypoints[0].position); int minPosition = 0; Transform[] copyWaypointsTransform = new Transform[circuit.Waypoints.Length]; for (int i = 0; i < circuit.Waypoints.Length; i++) { copyWaypointsTransform [i] = circuit.Waypoints [i].transform; if (Vector3.Distance(transform.position, circuit.Waypoints [i].position) < minDistance) { minDistance = Vector3.Distance(transform.position, circuit.Waypoints[i].position); minPosition = i; } } if (minPosition != 0) { int n = 0; for (int i = 0; i < circuit.Waypoints.Length; i++) { int sum = n + minPosition; if (sum >= circuit.Waypoints.Length - 1) { n = 0; minPosition = 0; } circuit.Waypoints[i] = copyWaypointsTransform[n + minPosition]; n++; } } // we use a transform to represent the point to aim for, and the point which // is considered for upcoming changes-of-speed. This allows this component // to communicate this information to the AI without requiring further dependencies. // You can manually create a transform and assign it to this component *and* the AI, // then this component will update it, and the AI can read it. if (target == null) { target = new GameObject(carTransform.name + " Waypoint Target").transform; } else { this.target = target; } Reset(); }
public void SetCarPathInfo(WaypointCircuit wayPath) { if (wayPath == null) { Debug.LogWarning("Unity:" + "wayPath is null"); return; } circuit = wayPath; if (AiCarCom == null) { AiCarCom = GetComponent <XKAiCarMoveCtrl>(); } AiCarCom.SetIsStopMoveCar(false); }
private float speed; // current speed of this object (calculated from delta since last frame) // setup script properties private void Start() { circuit = GameObject.Find("AIWayPoint").GetComponent <WaypointCircuit>(); // we use a transform to represent the point to aim for, and the point which // is considered for upcoming changes-of-speed. This allows this component // to communicate this information to the AI without requiring further dependencies. // You can manually create a transform and assign it to this component *and* the AI, // then this component will update it, and the AI can read it. if (target == null) { target = new GameObject(name + " Waypoint Target").transform; } Reset(); }
void Start() { UnityStandardAssets.Utility.WaypointCircuit cir = (UnityStandardAssets.Utility.WaypointCircuit)Instantiate(circuit, carpath); GameObject target = new GameObject(); target.transform.parent = transform; traker = new WaypointTracker(transform, cir, target.transform); detectionRange = 0; controller = GetComponent <CarController>(); rays = new Ray[3]; this.tag = "Vehicle"; }
public InventoryCar inventoryItemCar; // Use to know if LapCOunter is activate for the Race. // --> Initilization void Start() { if (inventoryItemCar) { b_ActivateLapCounter = inventoryItemCar.b_LapCounter; } GameObject tmpObj = GameObject.Find("Track_Path"); if (tmpObj) { Track = tmpObj.GetComponent <UnityStandardAssets.Utility.WaypointCircuit> (); // access the track (car path) } tmpObj = GameObject.Find("Game_Manager"); if (tmpObj) { gameManager = tmpObj.GetComponent <Game_Manager> (); // access the Game_Manager } //if (PlayerPrefs.GetInt ("TestMode") == 1) { // Init if Test Mode Activated if (gameManager.inventoryItemList.inventoryItem[0].b_TestMode == true) // Init if Test Mode Activated { InitCar(); } if (car [0] != null && Txt_P1_Lap) { Txt_P1_Lap.text = "Lap " + (car [0].iLapCounter).ToString() + "/" + lapNumber.ToString(); } if (car [1] != null && Txt_P2_Lap) { Txt_P2_Lap.text = "Lap " + (car [1].iLapCounter).ToString() + "/" + lapNumber.ToString(); } }
void OnEnable() { PathCircuit myScript = (PathCircuit)target; waypoint = myScript.gameObject.GetComponent <UnityStandardAssets.Utility.WaypointCircuit>(); }
private float speed; // current speed of this object (calculated from delta since last frame) // setup script properties public void Setup(WaypointCircuit circuit) { this.circuit = circuit; Reset(); }
public void SetWaypointCircuit(WaypointCircuit circuit) { this.circuit = circuit; }
public void SetWaypointCircuit(WaypointCircuit wpcircuit) { circuit = wpcircuit; }
//Circuit Handling and get/set functions /*Use this function if you want to choose the starting point of the circuit.*/ public void switchCircuit (WaypointCircuit c, int progress) { circuit = c; ProgressNum = progress; SetTarget(circuit.Waypoints[ProgressNum], false); }
private void getPassTrack() { switch (Mathf.RoundToInt(AIVehicleCarController.MaxSpeed).ToString()) { case "5": //string track = "PassingTrack" + userCarController.MaxSpeed.ToString(); passingTrack = (WaypointCircuit)GameObject.Find(VRAVEStrings.PassingTrack5).GetComponent<WaypointCircuit>(); passingSpeed = 15f; break; case "10": case "15": passingTrack = (WaypointCircuit)GameObject.Find(VRAVEStrings.PassingTrack25).GetComponent<WaypointCircuit>(); passingSpeed = 25f; break; case "20": passingTrack = (WaypointCircuit)GameObject.Find(VRAVEStrings.PassingTrack25).GetComponent<WaypointCircuit>(); passingSpeed = 25f; break; case "25": passingTrack = (WaypointCircuit)GameObject.Find(VRAVEStrings.PassingTrack25).GetComponent<WaypointCircuit>(); passingSpeed = 30f; break; default: passingTrack = (WaypointCircuit)GameObject.Find(VRAVEStrings.PassingTrack25).GetComponent<WaypointCircuit>(); passingSpeed = 30f; break; } }