Advertisement
Guest User

EnemyScript

a guest
May 20th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class Enemy : MonoBehaviour
  7. {
  8.     private Transform playerTransform;
  9.  
  10.     private NavMeshAgent nma;
  11.  
  12.     private Animator anim; // НОВОЕ
  13.  
  14.     private void Awake()
  15.     {
  16.         playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
  17.         nma = GetComponent<NavMeshAgent>();
  18.         anim = GetComponent<Animator>(); // НОВОЕ
  19.     }
  20.  
  21.     private void Update()
  22.     {
  23.         nma.SetDestination(playerTransform.position);
  24.         anim.SetFloat("Speed", Mathf.Lerp(0f, 1f, nma.velocity.magnitude / nma.speed)); // НОВОЕ
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement