[csharp] df

Viewer

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class pooplol : MonoBehaviour
  6. {
  7.     public Animator Toilet;
  8.     public AudioSource kmms;
  9.     public GameObject inttext;
  10.  
  11.     private bool isInteractable = false;
  12.  
  13.     void Start()
  14.     {
  15.         // Try to fetch the Animator component
  16.         Toilet = GetComponent<Animator>();
  17.         if (Toilet == null)
  18.         {
  19.             Debug.LogError("Animator component not found on the GameObject to which this script is attached.");
  20.         }
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         if (isInteractable && Input.GetKeyDown(KeyCode.E))
  26.         {
  27.             Debug.Log("E key pressed and interactable is true.");
  28.             Toilet.ResetTrigger("press");
  29.             Toilet.SetTrigger("press");
  30.         }
  31.     }
  32.  
  33.     void OnTriggerStay(Collider other)
  34.     {
  35.         if (other.CompareTag("MainCamera"))
  36.         {
  37.             inttext.SetActive(true);
  38.             isInteractable = true;
  39.             Debug.Log("MainCamera is within trigger area.");
  40.         }
  41.     }
  42.  
  43.     void OnTriggerExit(Collider other)
  44.     {
  45.         if (other.CompareTag("MainCamera"))
  46.         {
  47.             inttext.SetActive(false);
  48.             isInteractable = false;
  49.             Debug.Log("MainCamera has exited the trigger area.");
  50.         }
  51.     }
  52. }
  53.  

Editor

You can edit this paste and save as new:


File Description
  • df
  • Paste Code
  • 22 Apr-2024
  • 1.31 Kb
You can Share it: