Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- public class CheckpointOnTrigger : NetworkBehaviour
- {
- public Material noColor;
- public Material yesColor;
- int idx;
- int checkpointCount;
- bool isColliding;
- Renderer rend;
- void Start()
- {
- rend = GetComponent<Renderer>();
- rend.material = noColor;
- isColliding = false;
- idx = transform.GetSiblingIndex();
- checkpointCount = this.transform.parent.childCount;
- }
- void OnTriggerEnter(Collider collider)
- {
- if (collider.gameObject.GetComponentInParent<NetworkBehaviour>().isLocalPlayer)
- {
- if (isColliding) { return; }
- isColliding = true;
- rend.material = yesColor;
- if (this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == this.transform.parent.GetComponent<CheckpointController>().lastCheckpointPassed &&
- (this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == idx - 1 ||
- this.transform.parent.GetComponent<CheckpointController>().checkpointIdx == checkpointCount - 1 && idx == 0))
- {
- this.transform.parent.GetComponent<CheckpointController>().checkpointIdx = idx;
- if (idx == 0)
- {
- this.transform.parent.GetComponent<CheckpointController>().lapIdx++;
- }
- }
- this.transform.parent.GetComponent<CheckpointController>().lastCheckpointPassed = idx;
- }
- }
- void OnTriggerExit(Collider collider)
- {
- if (collider.gameObject.GetComponentInParent<NetworkBehaviour>().isLocalPlayer)
- {
- rend.material = noColor;
- isColliding = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement