Advertisement
Darkhitori

Emerald AI/Deactivate

Jan 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 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("Controls when an AI is deactivated while using the optimization system ")]
  10.     public class EAI_Deactivate : FsmStateAction
  11.     {
  12.         [RequiredField]
  13.         [CheckForComponent(typeof(Emerald_AI))]
  14.         public FsmOwnerDefault gameObject;
  15.  
  16.         public FsmBool everyFrame;
  17.  
  18.         Emerald_AI theScript;
  19.  
  20.  
  21.         public override void Reset()
  22.         {
  23.             gameObject = null;
  24.             everyFrame = true;
  25.         }
  26.        
  27.         public override void OnEnter()
  28.         {
  29.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  30.  
  31.             theScript = go.GetComponent<Emerald_AI>();
  32.  
  33.  
  34.             if (!everyFrame.Value)
  35.             {
  36.                 DoTheMagic();
  37.                 Finish();
  38.             }
  39.  
  40.         }
  41.  
  42.         public override void OnUpdate()
  43.         {
  44.             if (everyFrame.Value)
  45.             {
  46.                 DoTheMagic();
  47.             }
  48.         }
  49.  
  50.         void DoTheMagic()
  51.         {
  52.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  53.             if (go == null)
  54.             {
  55.                 return;
  56.             }
  57.  
  58.             theScript.Deactivate();            
  59.         }
  60.  
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement