Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class AgentControl : MonoBehaviour {
- public Transform target;
- NavMeshAgent agent;
- float originalSpeed;
- // Use this for initialization
- void Start () {
- agent = GetComponent<NavMeshAgent>();
- originalSpeed = agent.speed;
- }
- // Update is called once per frame
- void Update () {
- int mask = 1 << NavMesh.GetNavMeshLayerFromName("No Running");
- NavMeshHit navHit;
- agent.SamplePathPosition (-1, 0, out navHit);
- if ( (navHit.mask & mask) != 0)
- {
- agent.speed = originalSpeed * 0.3f;
- } else {
- agent.speed = originalSpeed;
- }
- agent.SetDestination( target.position );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment