Advertisement
Guest User

Untitled

a guest
May 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Networking;
  6.  
  7. public class CheckpointOnTrigger : NetworkBehaviour
  8. {
  9. public Material noColor;
  10. public Material yesColor;
  11. int idx;
  12. int checkpointCount;
  13. bool isColliding;
  14. Renderer rend;
  15.  
  16. void Start()
  17. {
  18. rend = GetComponent<Renderer>();
  19. rend.material = noColor;
  20. isColliding = false;
  21. idx = transform.GetSiblingIndex();
  22. checkpointCount = this.transform.parent.childCount;
  23. }
  24.  
  25. void OnTriggerEnter(Collider collider)
  26. {
  27. if (collider.gameObject.GetComponentInParent<NetworkBehaviour>().isLocalPlayer)
  28. {
  29. if (isColliding) { return; }
  30. isColliding = true;
  31. rend.material = yesColor;
  32. if (this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == this.transform.parent.GetComponent<CheckpointController>().lastCheckpointPassed &&
  33. (this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == idx - 1 ||
  34. this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == checkpointCount - 1 && idx == 0))
  35. {
  36. this.transform.parent.GetComponent<CheckpointController>().checkpointIdx = idx;
  37.  
  38. if (idx == 0)
  39. {
  40. this.transform.parent.GetComponent<CheckpointController>().lapIdx++;
  41. }
  42. }
  43. this.transform.parent.GetComponent<CheckpointController>().lastCheckpointPassed = idx;
  44. }
  45. }
  46.  
  47. void OnTriggerExit(Collider collider)
  48. {
  49. if (collider.gameObject.GetComponentInParent<NetworkBehaviour>().isLocalPlayer)
  50. {
  51. rend.material = noColor;
  52. isColliding = false;
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement