Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class NavigationSimulation : MonoBehaviour
{
public GameObject[] checkpoints;
private int currentCheckpointIndex = 0;
[SerializeField] TMP_Text checkpointText;
[Space(8)]
[SerializeField]
private bool deactivateAfterStart = true;
// Start is called before the first frame update
void Start()
{
if (deactivateAfterStart)
foreach (GameObject child in checkpoints)
{
child.SetActive(false);
}
}
// Update is called once per frame
void Update()
{
}
private void ActivateCheckpoint(int contentId)
{
checkpoints[contentId - 1].SetActive(true);
}
private void DeactivateCheckpoint(int contentId)
{
checkpoints[contentId - 1].SetActive(false);
}
private void OnTriggerEnter(Collider collision)
{
Debug.Log("Collision detected at: " + collision.gameObject.name + " Object: " + checkpoints[currentCheckpointIndex].name);
// Check if the collided object is the current checkpoint
string n = checkpoints[currentCheckpointIndex].name;
int id = int.Parse(collision.gameObject.name.Split(' ')[2]);
int id_content = int.Parse(checkpoints[currentCheckpointIndex].name.Split(' ')[1]);
if (id == id_content)
{
// Deactivate the current checkpoint
if (currentCheckpointIndex != 0) DeactivateCheckpoint(currentCheckpointIndex);
// Check if there are more checkpoints
if (currentCheckpointIndex < checkpoints.Length)
{
if (currentCheckpointIndex < checkpoints.Length - 1) currentCheckpointIndex++;
// Activate the next checkpoint
checkpointText.text = "Checkpoint " + currentCheckpointIndex;
ActivateCheckpoint(currentCheckpointIndex);
}
else
{
// All checkpoints reached, do something
Debug.Log("All checkpoints reached!");
}
}
}
}