Advertisement
buryo

Unity

Dec 3rd, 2017
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Road : MonoBehaviour {
  6.     UnityEngine.AI.NavMeshAgent playerAgent;
  7.     float speed = 15f;
  8.     private bool onRoad = false;
  9.  
  10.     void Update () {
  11.         if (onRoad) {
  12.             playerAgent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
  13.             playerAgent.speed = speed;
  14.         }
  15.     }
  16.  
  17.     void OnTriggerEnter(Collider other){
  18.         if (other.gameObject.CompareTag("Road")) {
  19.             onRoad = true;
  20.         }
  21.     }
  22.  
  23.     void OnTriggerExit(Collider other){
  24.         if (other.gameObject.CompareTag("Road")) {
  25.             onRoad = false;
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement