Advertisement
Darkhitori

Emerald AI/UpdateTargetTags

Jan 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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("Clears an AI's current target tags and updates them to the ones in the parameters. ")]
  10.     public class EAI_UpdateTargetTags : FsmStateAction
  11.     {
  12.         [RequiredField]
  13.         [CheckForComponent(typeof(Emerald_AI))]
  14.         public FsmOwnerDefault gameObject;
  15.        
  16.         public FsmString NewAITag;
  17.         public FsmString Tag1;
  18.         public FsmString Tag2;
  19.         public FsmString Tag3;
  20.         public FsmString Tag4;
  21.         public FsmString Tag5;
  22.  
  23.         public FsmBool everyFrame;
  24.  
  25.         Emerald_AI theScript;
  26.  
  27.  
  28.         public override void Reset()
  29.         {
  30.             gameObject = null;
  31.             NewAITag = "";
  32.             Tag1 = "";
  33.             Tag2 = "";
  34.             Tag3 = "";
  35.             Tag4 = "";
  36.             Tag5 = "";
  37.             everyFrame = true;
  38.         }
  39.        
  40.         public override void OnEnter()
  41.         {
  42.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  43.  
  44.             theScript = go.GetComponent<Emerald_AI>();
  45.  
  46.  
  47.             if (!everyFrame.Value)
  48.             {
  49.                 DoTheMagic();
  50.                 Finish();
  51.             }
  52.  
  53.         }
  54.  
  55.         public override void OnUpdate()
  56.         {
  57.             if (everyFrame.Value)
  58.             {
  59.                 DoTheMagic();
  60.             }
  61.         }
  62.  
  63.         void DoTheMagic()
  64.         {
  65.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  66.             if (go == null)
  67.             {
  68.                 return;
  69.             }
  70.  
  71.             theScript.UpdateTargetTags(NewAITag.Value, Tag1.Value, Tag2.Value, Tag3.Value, Tag4.Value, Tag5.Value);            
  72.         }
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement