Darkhitori

vThirdPersonInput/MoveCharacter

Jan 12th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 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/vThirdPersonInput")]
  10.     [Tooltip(" ")]
  11.     public class vTPI_MoveCharacter : FsmStateAction
  12.     {
  13.         [RequiredField]
  14.         [CheckForComponent(typeof(vThirdPersonInput))]
  15.         public FsmOwnerDefault gameObject;
  16.        
  17.         public enum MoveCharacter
  18.         {
  19.             position_rotateToDirection,
  20.             transform_rotateToDirection
  21.         }
  22.        
  23.         public MoveCharacter methods;
  24.        
  25.         public FsmVector3 position;
  26.        
  27.         public FsmGameObject transform;
  28.        
  29.         public FsmBool rotateToDirection;
  30.        
  31.         public FsmBool everyFrame;
  32.  
  33.         vThirdPersonInput theScript;
  34.  
  35.  
  36.         public override void Reset()
  37.         {
  38.             gameObject = null;
  39.             methods = MoveCharacter.position_rotateToDirection;
  40.             position = new Vector3(0,0,0);
  41.             transform = null;
  42.             rotateToDirection = true;
  43.             everyFrame = true;
  44.         }
  45.        
  46.         public override void OnEnter()
  47.         {
  48.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  49.  
  50.             theScript = go.GetComponent<vThirdPersonInput>();
  51.  
  52.  
  53.             if (!everyFrame.Value)
  54.             {
  55.                 DoTheMagic();
  56.                 Finish();
  57.             }
  58.  
  59.         }
  60.  
  61.         public override void OnUpdate()
  62.         {
  63.             if (everyFrame.Value)
  64.             {
  65.                 DoTheMagic();
  66.             }
  67.         }
  68.  
  69.         void DoTheMagic()
  70.         {
  71.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  72.             if (go == null)
  73.             {
  74.                 return;
  75.             }
  76.            
  77.             switch (methods)
  78.             {
  79.             case MoveCharacter.position_rotateToDirection:
  80.                 theScript.MoveCharacter(position.Value, rotateToDirection.Value);
  81.                 break;
  82.             case MoveCharacter.transform_rotateToDirection:
  83.                 theScript.MoveCharacter(transform.Value.transform, rotateToDirection.Value);
  84.                 break;
  85.             }
  86.                        
  87.         }
  88.  
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment