Created
May 12, 2023 00:05
-
-
Save sabotai/2a58b13572a93ab406664d24f7647a11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class TriggerCounterTeleport : MonoBehaviour | |
{ | |
public Transform[] requiredAreasToVisit; | |
public bool[] requiredAreasVisited; | |
public Transform teleportPositionMarker; | |
public Transform thingToTeleport; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
for (int i = 0;i < requiredAreasVisited.Length; i++){ | |
requiredAreasVisited[i] = false; | |
} | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
int howManyVisited = 0; | |
for (int i = 0; i < requiredAreasToVisit.Length; i++){ | |
if (requiredAreasVisited[i]){ | |
howManyVisited++; | |
} | |
} | |
if (howManyVisited == requiredAreasToVisit.Length){ | |
thingToTeleport.position = teleportPositionMarker.position; | |
} | |
} | |
void OnTriggerEnter(Collider col){ | |
for (int i = 0; i < requiredAreasToVisit.Length; i++){ | |
if (col.transform == requiredAreasToVisit[i]) | |
requiredAreasVisited[i] = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment