duck

Robot navmesh script step 1

Nov 14th, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Robot : MonoBehaviour {
  5.    
  6.     public Transform target;
  7.    
  8.     NavMeshAgent agent;
  9.     Animation avatar;
  10.    
  11.     // Use this for initialization
  12.     void Start () {
  13.        
  14.         agent = GetComponent<NavMeshAgent>();
  15.        
  16.         avatar = GetComponentInChildren<Animation>();
  17.        
  18.     }
  19.    
  20.     // Update is called once per frame
  21.     void Update () {
  22.        
  23.         agent.SetDestination( target.position );
  24.        
  25.         if ( agent.velocity.magnitude > 0.1f )
  26.         {
  27.             avatar.CrossFade("run");
  28.         } else {
  29.             avatar.CrossFade("idle");
  30.         }
  31.        
  32.        
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment