Advertisement
Darkhitori

Emerald AI/Damage

Jan 16th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. namespace HutongGames.PlayMaker.Actions
  7. {
  8.     [ActionCategory("Emerald AI")]
  9.     [Tooltip("Damages an AI according to the DamageAmount parameter. ")]
  10.     public class EAI_Damage : FsmStateAction
  11.     {
  12.         [RequiredField]
  13.         [CheckForComponent(typeof(Emerald_AI))]
  14.         public FsmOwnerDefault gameObject;
  15.        
  16.         public FsmInt damageAmount;
  17.        
  18.         public Emerald_AI.TargetType typeOfTarget;
  19.  
  20.         public FsmBool everyFrame;
  21.  
  22.         Emerald_AI theScript;
  23.  
  24.  
  25.         public override void Reset()
  26.         {
  27.             gameObject = null;
  28.             damageAmount = null;
  29.             typeOfTarget =  Emerald_AI.TargetType.AI;
  30.             everyFrame = true;
  31.         }
  32.        
  33.         public override void OnEnter()
  34.         {
  35.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  36.  
  37.             theScript = go.GetComponent<Emerald_AI>();
  38.  
  39.  
  40.             if (!everyFrame.Value)
  41.             {
  42.                 DoTheMagic();
  43.                 Finish();
  44.             }
  45.  
  46.         }
  47.  
  48.         public override void OnUpdate()
  49.         {
  50.             if (everyFrame.Value)
  51.             {
  52.                 DoTheMagic();
  53.             }
  54.         }
  55.  
  56.         void DoTheMagic()
  57.         {
  58.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  59.             if (go == null)
  60.             {
  61.                 return;
  62.             }
  63.            
  64.             theScript.Damage(damageAmount.Value, typeOfTarget);            
  65.         }
  66.  
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement