SHARE
TWEET

Untitled

a guest Jun 19th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using UnityEngine;
  3.  
  4. public class Enemy : MovingObject {
  5.  
  6.     public int playedDamage;
  7.  
  8.  
  9.  
  10.     private Animator animator;
  11.     private Transform target;
  12.     private bool skipMove;
  13.  
  14.  
  15.     protected override void Start ()
  16.     {
  17.         animator = GetComponent<Animator> ();
  18.         target = GameObject.FindGameObjectWithTag ("Player").transform;
  19.     }
  20.  
  21.     protected override void AttemptMove <T> (int xDir, int yDir)
  22.     {
  23.         if (skipMove)
  24.         {
  25.             skipMove = false;
  26.             return;
  27.         }
  28.  
  29.         base.AttemptMove <T> (xDir, yDir);
  30.  
  31.         skipMove = true;
  32.     }
  33.  
  34.     public void MoveEnemy()
  35.     {
  36.         int xDir = 0;
  37.         int yDir = 0;
  38.  
  39.         if (Mathf.Abs (target.position.x - transform.position.x) < float.Epsilon)
  40.             yDir = target.position.y > transform.position.y ? 1 : -1;
  41.         else
  42.             xDir = target.position.x > transform.position.x ? 1 : -1;
  43.  
  44.         AttemptMove <Player> (xDir, yDir);
  45.     }
  46.  
  47.     protected override void OnCantMove <T> (T component)
  48.     {
  49.         Player hitPlayer = component as Player;
  50.  
  51.         hitPlayer.LoseFood (playerDamage);
  52.     }
  53. }
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top