Advertisement
i-Xuup

Detección colliders

Nov 17th, 2024
52
0
6 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. public float detectionRadius = 1.5f;
  2. private bool isInsideTrigger;
  3. public LayerMask triggerLayer;
  4.  
  5. void Update()
  6. {
  7.     Collider[] hits = Physics.OverlapSphere(transform.position, detectionRadius, triggerLayer);
  8.  
  9.     if (hits.Length > 0 && !isInsideTrigger)
  10.     {
  11.         isInsideTrigger = true;
  12.     }
  13.  
  14.     if (!preLevel && hits.Length > 0 && isInsideTrigger && shortCollider.bounds.Intersects(hits[0].bounds))
  15.     {
  16.         Debug.Log(hits[0].gameObject.name);
  17.         playerCanvas.transform.rotation = Quaternion.Euler(30f, -32.5f, 0f);
  18.         GameObject interactiveObject = hits[0].gameObject;
  19.  
  20.         if (interactiveObject.CompareTag("Prepare Drink Table") && !objectAnalyserOccupaid)
  21.         {
  22.             Debug.Log("este se debe activar solo una vez");
  23.             objectAnalyserOccupaid = true;
  24.             int tempID = interactiveObject.transform.parent.GetComponent<MachinesID>().machineID;
  25.             if (tempID == 1)
  26.             {
  27.                 ActivePlayerSlider("prepare drink");
  28.             }
  29.             else
  30.             {
  31.                 bartenderController.playerIsUsingSystem = true;
  32.                 ActivePlayerSlider("prepare drink 2");
  33.             }
  34.         }
  35.     }
  36.  
  37.     if (hits.Length > 0 && isInsideTrigger && boolInteractions[0] && playerSlider.value < 1)
  38.     {
  39.         playerCanvas.transform.rotation = Quaternion.Euler(30f, -32.5f, 0f);
  40.         int drinksInTable = serveDrinkTable1.drinksMadeCounter;
  41.         if (drinksInTable < drinksTableMaxCapacity)
  42.         {
  43.             ActiveSlider("prepare drink");
  44.         }
  45.     }
  46.  
  47.     //si Saliste de algún trigger con el layer triggerLayer (no lee todos los colliders)
  48.     if (hits.Length == 0 && isInsideTrigger)
  49.     {
  50.         isInsideTrigger = false;
  51.         playerSlider.value = 0;
  52.         playerCanvas.SetActive(false);
  53.         for (int i = 0; i < boolInteractions.Length; i++)
  54.         {
  55.             boolInteractions[i] = false;
  56.         }
  57.         MachineController.Instance.DesactivateInteractions();
  58.         if (bartenderController != null && bartenderController.playerIsUsingSystem)
  59.         {
  60.             bartenderController.playerIsUsingSystem = false;
  61.         }
  62.         objectAnalyserOccupaid = false;
  63.     }
  64. }
  65.  
  66. void ActiveSlider(string interactiveObject)
  67. {
  68.     playerSlider.value += (Time.deltaTime * playerInteraction);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement