/// <summary> /// Iterate the vehicle's checkpoint number when it passes through the checkpoint /// </summary> void OnTriggerEnter(Collider other) //when a vehicle passes through the checkpoint { GameObject Racer = GameObject.Find(other.name); //get the agent who entered the checkpoint's name //iterate the vehicle's checkpoint number if (other.name == "Player") //if the vehicle is the player { PlayerMovement PlayerScript = Racer.GetComponent <PlayerMovement> (); if (checkpointNumber == 0 && PlayerScript.getcurrentCheckpointNo() == 300) //if completed a lap { PlayerScript.incrementLap(); //increment the lap positionTracker.updateRacerLap(other.name); //and update it in the position tracker GameObject.Find("GUICanvas").GetComponent <GUITimer>().ResetTime(); //and reset the laptime } PlayerScript.setcurrentCheckpointNo(checkpointNumber); //then update the checkpoint number UpdateCheckpointPosition(Racer, checkpointNumber); //update the position tracker with the new checkpoint } else //else it is not player but a racer { AIRacer2 RacerScript = Racer.GetComponent <AIRacer2> (); if (checkpointNumber == 0 && RacerScript.getcurrentCheckpointNo() == 300) { RacerScript.incrementLap(); positionTracker.updateRacerLap(other.name); } RacerScript.setcurrentCheckpointNo(checkpointNumber); UpdateCheckpointPosition(Racer, checkpointNumber); } }
/// <summary> /// Iterate the vehicle's checkpoint number when it passes through the checkpoint /// </summary> void OnTriggerEnter(Collider other) //when a vehicle passes through the checkpoint { if (other.tag == "Player01" || other.tag == "Player02") //if the vehicle is the player { PlayerMovement playerScript = other.gameObject.GetComponent <PlayerMovement> (); // Debug.Log ("checkpointNumber: " + checkpointNumber + "PlayerScript.GetCurrentCheckpointNo(): " + playerScript.GetCurrentCheckpointNo()); if (checkpointNumber == 0 && playerScript.GetCurrentCheckpointNo() == 20) //if completed a lap { playerScript.IncrementLap(); //increment the lap positionTracker.updateRacerLap(other.name); //and update it in the position tracker } playerScript.SetCurrentCheckpointNo(checkpointNumber); //then update the checkpoint number UpdateCheckpointPosition(other.gameObject, checkpointNumber); //update the position tracker with the new checkpoint } }