Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Road : MonoBehaviour {
- UnityEngine.AI.NavMeshAgent playerAgent;
- float speed = 15f;
- private bool onRoad = false;
- void Update () {
- if (onRoad) {
- playerAgent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
- playerAgent.speed = speed;
- }
- }
- void OnTriggerEnter(Collider other){
- if (other.gameObject.CompareTag("Road")) {
- onRoad = true;
- }
- }
- void OnTriggerExit(Collider other){
- if (other.gameObject.CompareTag("Road")) {
- onRoad = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement