Guest User

Untitled

a guest
Feb 19th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Zombie : MonoBehaviour {
  5.  
  6.     [SerializeField]
  7.     private Rigidbody2D zombieRB;
  8.  
  9.     [SerializeField]
  10.     private AStar aStar;
  11.  
  12.     public float speed = 0.005f;
  13.  
  14.     Vector3 nextNodePosition;
  15.  
  16.     // Update is called once per frame
  17.     void Awake()
  18.     {
  19.         nextNodePosition = new Vector3(0, 0, 0);
  20.         zombieRB = GetComponent<Rigidbody2D>();
  21.         aStar = GetComponent<AStar>();
  22.         //zombieRB.AddForce(zombieRB.transform.up * 8.2f);
  23.     }
  24.  
  25.     void FixedUpdate()
  26.     {
  27.  
  28.     }
  29.  
  30.     void Update()
  31.     {
  32.  
  33.         if (Input.GetKeyDown("m"))
  34.         {
  35.  
  36.         }
  37.         GetNextNodePos(ref nextNodePosition);
  38.         float step = speed * Time.deltaTime;
  39.         transform.position = Vector3.MoveTowards(transform.position, nextNodePosition, step);
  40.  
  41.     }
  42.  
  43.  
  44.  
  45.     private void GetNextNodePos(ref Vector3 nextNodePosition)
  46.     {
  47.         if (aStar.isRunning)
  48.         {
  49.             nextNodePosition = aStar.nextNode.transform.position;
  50.         }
  51.     }
  52.  
  53.  
  54. }
Add Comment
Please, Sign In to add comment