49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| using UnityEngine.UI;
 | |
| 
 | |
| public class TeleportLocationCollider : MonoBehaviour
 | |
| {
 | |
|     public TeleportLocation parent;
 | |
|     private void OnTriggerEnter(Collider other)
 | |
|     {
 | |
|         MenuReference reference = other.GetComponent<MenuReference>();
 | |
|         if (reference == null) return;
 | |
| 
 | |
|         List<MenuTeleportButton> buttonsList = reference.buttons;
 | |
|         MenuTeleportButton button = findCorrespondingButton(buttonsList);
 | |
|         if (button != null)
 | |
|         {
 | |
|             button.SetStateSelected();
 | |
|         }
 | |
|     }
 | |
|     private void OnTriggerExit(Collider other)
 | |
|     {
 | |
|         MenuReference reference = other.GetComponent<MenuReference>();
 | |
|         if (reference == null) return;
 | |
| 
 | |
|         List<MenuTeleportButton> buttonsList = other.GetComponent<MenuReference>().buttons;
 | |
|         MenuTeleportButton button = findCorrespondingButton(buttonsList);
 | |
| 
 | |
|         if (button != null)
 | |
|         {
 | |
|             button.SetStateDefault();
 | |
|         }
 | |
| 
 | |
|         //Debug.Log(other.name + " exited the area");
 | |
|     }
 | |
|     private MenuTeleportButton findCorrespondingButton(List<MenuTeleportButton> buttons) 
 | |
|     {
 | |
|         foreach (MenuTeleportButton button in buttons)
 | |
|         {
 | |
|             if (button.TargetName.Equals(parent.Name))
 | |
|             {
 | |
|                 return button;
 | |
|             }
 | |
|         }
 | |
|         Debug.Log("Teleport location of " + parent.Name + " was unable to find the button triggering it");
 | |
|         return null;
 | |
|     }
 | |
| }
 |