Advertisement
Guest User

Untitled

a guest
Feb 26th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TriggerEvent : MonoBehaviour
  6. {
  7. public GameObject lightBulb = null;
  8. public GameObject wall = null;
  9. public AudioSource lightBulbOnAS = null;
  10. public AudioClip lightBulbOn = null;
  11.  
  12. void OnTriggerEnter ( Collider other )
  13. {
  14. if (other.name == "player")
  15. {
  16. // turn on light bulb
  17. lightBulb.SetActive (true);
  18.  
  19. if (lightBulbOnAS == null)
  20. lightBulbOnAS = GetComponent<AudioSource>();
  21.  
  22. lightBulbOnAS.PlayOneShot(lightBulbOn);
  23. //audio.PlayOneShot(lightBulbOn);
  24.  
  25. wall.GetComponent<ObjectScaling>().EnableScale();
  26. wall.GetComponent<ObjectColor>().EnableColor();
  27.  
  28. Debug.Log ("LightBulb turned on");
  29. }
  30. }
  31.  
  32. void OnTriggerExit (Collider other)
  33. {
  34. if (other.name == "player")
  35. {
  36. // Turn off light bulb
  37. lightBulb.SetActive (false);
  38.  
  39. lightBulbOnAS.Stop ();
  40.  
  41. wall.GetComponent<ObjectScaling>().DisableScale();
  42. wall.GetComponent<ObjectColor>().DisableColor();
  43.  
  44. Debug.Log ("LightBulb turned off");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement