public void CheckpointReached(CheckpointSingle checkpoint)
    {
        //right checkpoint
        if (checkpointList.IndexOf(checkpoint) == nextCheckpointIndex)
        {
            checkpoint.GetComponent <MeshRenderer>().material = wrongCheckpoint;

            Debug.Log(nextCheckpointIndex);
            OSCHandler.Instance.SendMessageToClient("pd", "/unity/checkpoint", nextCheckpointIndex);
            nextCheckpointIndex = (nextCheckpointIndex + 1) % checkpointList.Count;

            checkpointsTransform.GetChild(nextCheckpointIndex).GetComponent <MeshRenderer>().material = rightCheckpoint;

            if (nextCheckpointIndex == 1)
            {
                laps++;
            }
        }
        //wrong checkpoint
        else
        {
            Debug.Log("Wrong");
            //wrong sound maybe?
        }
    }
    private void Awake()
    {
        Transform checkpointsTransform = transform.Find("Checkpoints");

        checkpointSingleList = new List <CheckpointSingle>();
        foreach (Transform checkpointSingleTransform in checkpointsTransform)
        {
            CheckpointSingle checkpointSingle = checkpointSingleTransform.GetComponent <CheckpointSingle>();
            checkpointSingle.SetTrackCheckpoints(this);
            checkpointSingleList.Add(checkpointSingle);
        }
        nextCheckpointIndex = 0;
    }
    private void Awake()
    {
        checkpointsTransform = GetComponent <Transform>();

        //initialized list of checkpoints and connects them to the tracker
        //checkpointsTransform = transform.Find("Checkpoints");

        foreach (Transform checkPointSingleTransform in checkpointsTransform)
        {
            CheckpointSingle checkpoint = checkPointSingleTransform.GetComponent <CheckpointSingle>();
            checkpoint.setTrackCheckpoints(this);
            checkpointList.Add(checkpoint);
        }
    }
    public void CarThroughCheckpoint(CheckpointSingle checkpointSingle, Transform carTransfrom)
    {
        int nextCheckpointSingleIndex = nextCheckpointSingleIndexList[carTransformList.IndexOf(carTransfrom)];

        if (checkpointSingleList.IndexOf(checkpointSingle) == nextCheckpointSingleIndex)
        {
            CheckpointSingle correctCheckpointSingle = checkpointSingleList[nextCheckpointSingleIndex];
            nextCheckpointSingleIndexList[carTransformList.IndexOf(carTransfrom)] = (nextCheckpointSingleIndex + 1) % checkpointSingleList.Count;
            OnPlayerCorrectCheckpoint?.Invoke(this, EventArgs.Empty);
        }
        else
        {
            OnPlayerWrongCheckpoint?.Invoke(this, EventArgs.Empty);
        }
    }
 public void PlayerThroughCheckpoint(CheckpointSingle checkpointSingle, Transform playerTransform)
 {
     if (checkpointSingleList.IndexOf(checkpointSingle) == nextCheckpointIndex)
     {
         nextCheckpointIndex = (nextCheckpointIndex + 1) % checkpointSingleList.Count;
         OnPlayerCorrectCheckpoint?.Invoke(this, new CarCheckpointEventArgs {
             carTransform = playerTransform
         });
     }
     else
     {
         OnPlayerWrongCheckpoint?.Invoke(this, new CarCheckpointEventArgs {
             carTransform = playerTransform
         });
     }
 }
示例#6
0
 public void PlayerThroughCheckpoint(CheckpointSingle checkpointSingle)
 {
     if (checkpointSingleList.IndexOf(checkpointSingle) == nextCheckpointSingleIndex)
     {
         Debug.Log("Correct");
         checkpointSingle.transform.gameObject.SetActive(false);
         if (nextCheckpointSingleIndex == checkpointSingleList.Count - 1)
         {
             end.SetActive(true);
         }
         else
         {
             nextCheckpointSingleIndex++;
             checkpointSingleList[nextCheckpointSingleIndex].transform.gameObject.SetActive(true);
         }
     }
 }