Advertisement
Darkhitori

vThirdPersonController/CheckTriggers

Jan 12th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Invector.CharacterController;
  6.  
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("Invector/vThirdPersonController")]
  10.     [Tooltip("Call this in OnTriggerEnter or OnTriggerStay to check if enter in triggerActions ")]
  11.     public class vTPC_CheckTriggers : FsmStateAction
  12.     {
  13.         [RequiredField]
  14.         [CheckForComponent(typeof(vThirdPersonController))]
  15.         public FsmOwnerDefault gameObject;
  16.        
  17.         [ObjectType(typeof(Collider))]
  18.         public FsmObject other;
  19.        
  20.         public FsmEvent sendEvent;
  21.        
  22.         public FsmBool everyFrame;
  23.  
  24.         vThirdPersonController theScript;
  25.  
  26.  
  27.         public override void Reset()
  28.         {
  29.             gameObject = null;
  30.             other = null;
  31.             sendEvent = null;
  32.             everyFrame = true;
  33.         }
  34.        
  35.         public override void OnEnter()
  36.         {
  37.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  38.  
  39.             theScript = go.GetComponent<vThirdPersonController>();
  40.  
  41.  
  42.             if (!everyFrame.Value)
  43.             {
  44.                 DoTheMagic();
  45.                 Finish();
  46.             }
  47.  
  48.         }
  49.  
  50.         public override void OnUpdate()
  51.         {
  52.             if (everyFrame.Value)
  53.             {
  54.                 DoTheMagic();
  55.             }
  56.         }
  57.  
  58.         void DoTheMagic()
  59.         {
  60.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  61.             if (go == null)
  62.             {
  63.                 return;
  64.             }
  65.             var vOther = other.Value as Collider;
  66.             if (vOther == null)
  67.             {
  68.                 return;
  69.             }
  70.            
  71.             theScript.CheckTriggers(vOther);
  72.             if (sendEvent == null)
  73.             {
  74.                 return;
  75.             }
  76.             else
  77.             {
  78.                 Fsm.Event(sendEvent);
  79.             }
  80.         }
  81.  
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement