Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / BridgeBehaviour.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BridgeBehaviour : MonoBehaviour
  5. {
  6. private Collider coll;
  7. public Color bridgeColor;
  8. public int bridgeNumber;
  9. public bool isCollidable;
  10. public ConditionCkecker condition;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. coll = GetComponent<Collider>();
  15. condition = GetComponent<ConditionCkecker>();
  16. }
  17. private void Update()
  18. {
  19. if (condition != null)
  20. {
  21. isCollidable = condition.CheckConditions();
  22. }
  23. }
  24. private void OnTriggerEnter(Collider collider)
  25. {
  26. Debug.Log("col enter");
  27. if (collider.gameObject.CompareTag("Player"))
  28. {
  29. Physics.IgnoreCollision(collider, coll, !isCollidable);
  30. }
  31. else
  32. if (collider.gameObject.CompareTag("Box"))
  33. {
  34. BoxScript boxScript;
  35. if (collider.gameObject.TryGetComponent<BoxScript>(out boxScript))
  36. {
  37. if (boxScript.boxNumber != bridgeNumber)
  38. {
  39. Physics.IgnoreCollision(collider, coll, !isCollidable);
  40. }
  41. }
  42. }
  43. }
  44. }