Darkhitori

vThirdPersonController/RotateWithAnotherTransform

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