void Update();部ですが攻撃モーションのコンボを作りたくて一定の間隔ないでZキーを押すと振り戻す前の攻撃コンボ2が再生されるという仕様を実装しようと思うのですが現在のモーション時間を知りたいです。調べると__float f += Time.deltatime;__を使う方法を参考サイトで調べましたがちょと違う?適当?に思うのでモーションの再生時間が知りたいです。また参考サイト2はちょっとやり方が違うみたいで参考にならないです。
参考サイト: https://gametukurikata.com/program/continuityattack
using UnityEngine; //using System.Collections.Generic; using System.Collections; public class Controller : MonoBehaviour { /* Ik 関係 Vector3 rightFootPos = new Vector3(0, 0, 0); Vector3 leftFootPos = new Vector3(0, 0, 0); Quaternion rightFootRot = new Quaternion(0, 0, 0, 0); Quaternion leftFootRot = new Quaternion(0, 0, 0, 0); bool isRightFootIK = false; bool isLeftFootIK = false; float RightIkWeight = 0; float LeftIkWeight = 0; Vector3 rayPositionOffset = new Vector3(0, 0, 0); float rayRange = 1.0f; float offset = 0.1f; */ private Vector3 vt; private float combo_time = 0; private float input_h; private float input_v; private Vector3 move; private float walk_speed;//移動速度 private Vector3 move_direction;//移動方向 private CharacterController cc; private Animator anim; /*判定*/ private bool isAttack = false; private bool isAttack_start = false; private bool isAttack_end = false; private bool isJump = false; private bool isGround = true; private AnimatorClipInfo[] ClipInfo; public GameObject []effects; // public GameObject p; private GameObject GroundCheck; public Transform LeftHand_IK;// //public GameObject LeftHand_target;// //private Transform LeftHand_IK = LeftHand_target; private readonly int all_effects = 4; float j; private bool []combo = new bool[4]; private float comboTime = 1; // public GameObject groundCheck; // Use this for initialization void Start() { j = 0; move = new Vector3(0, 0, 0); cc = GetComponent<CharacterController>(); anim = GetComponent<Animator>(); walk_speed = 7; ClipInfo = anim.GetCurrentAnimatorClipInfo(0); for (int i = 0; i< all_effects; i++) { combo[i] = false; } GroundCheck = transform.Find("GroundCheck").gameObject; GroundCheck.GetComponent<Ground>().isGround = false; } void Move_Mng() { input_h = Input.GetAxis("Horizontal"); input_v = Input.GetAxis("Vertical"); Vector3 move_z = new Vector3(); Vector3 move_x = new Vector3(); move_z = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized * input_v; move_x = Camera.main.transform.right * input_h; move_direction = move_x + move_z; move_direction.y = 0; move.x = move_direction.x * walk_speed; move.z = move_direction.z * walk_speed; // Debug.Log("move.x: \n" + move.x); // Debug.Log("move.z: \n" + move.z); if (move_direction != Vector3.zero) { move_direction.y = 0; transform.rotation = Quaternion.LookRotation(move_direction.normalized); } /*ジャンプ*/ if(isJump == true) { Debug.Log("aaa"); move.y += 2; if(move.y > 40) { isJump = false; } }else if (GroundCheck.GetComponent<Ground>().isGround == false && isJump == false) { move.y = - 20; } } void Animator_Mng() { anim.SetFloat("move_forward", getInput()); } float getSpeed() { return Mathf.Abs(Mathf.Sqrt(Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); // return 100;//Mathf.Abs(Mathf.Sqrt( Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); } float getInput() { return Mathf.Abs(Mathf.Sqrt(Mathf.Abs(input_h * input_h) + Mathf.Abs(input_v * input_v))); // return 100;//Mathf.Abs(Mathf.Sqrt( Mathf.Abs(move.x * move.x) + Mathf.Abs(move.z * move.z))); } //IKの重みを設定する void SetIkWeight(AvatarIKGoal _goal, float _posWeight, float _rotWeight) { anim.SetIKPositionWeight(_goal, Mathf.Clamp(_posWeight, 0.5f, 1.0f)); anim.SetIKRotationWeight(_goal, Mathf.Clamp(_rotWeight, 0.5f, 1.0f)); } //IKを指定して固定させる void SetIk(AvatarIKGoal goal, Vector3 _pos, Quaternion _rot, bool isAddIKPosition = false) { if (isAddIKPosition) _pos += anim.GetIKPosition(goal); anim.SetIKPosition(goal, _pos); anim.SetIKRotation(goal, _rot); } IEnumerator combo_corutine_end() { yield return new WaitForSeconds(0.5f); for (int i = 0; i < all_effects; i++) { combo[i] = false; } } IEnumerator combo_corutine(int number) { Instantiate(effects[number], transform.position, transform.rotation); anim.SetTrigger("attackCombo_1"); yield return new WaitForSeconds(0.5f); combo[number] = false; } // Update is called once per frame void Update() { ClipInfo = anim.GetCurrentAnimatorClipInfo(0); /*ジャンプ処理*/ if ( Input.GetKey(KeyCode.Space) == true )//&& GroundCheck.GetComponent<Ground>().isGround == true && isJump == false) { Debug.Log("Jump"); // anim.SetTrigger("jump"); isJump = true; }else //if(isJump == true && GroundCheck.GetComponent<Ground>().isGround == false) { } if (Input.GetKeyDown(KeyCode.Z) == true ) //&& (ClipInfo[0].clip.name == "EllenIdle") ) { isAttack = true; combo[0] = true; }else { isAttack = false; } if (Input.GetKey(KeyCode.LeftShift) == true || Input.GetKey(KeyCode.RightShift) == true) { anim.SetBool("Run_shift", true); } else { anim.SetBool("Run_shift", false); } } ////////////////////////////////////////////////////////////////////////////////////////////// void FixedUpdate() { Move_Mng(); Animator_Mng(); cc.Move(move * Time.deltaTime); } ////////////////////////////////////////////////////////////////////////////////////////////// private void OnAnimatorIK() { Debug.Log("aaa"); anim.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1); anim.SetIKPosition(AvatarIKGoal.LeftHand, LeftHand_IK.position); anim.SetIKRotation(AvatarIKGoal.LeftHand, LeftHand_IK.rotation); /* //右手を固定 if (LeftHand_IK != null) { SetIkWeight(AvatarIKGoal.LeftHand, 1.0f, 1.0f); SetIk(AvatarIKGoal.LeftHand, LeftHand_IK.position, LeftHand_IK.rotation); } */ } void MeleeAttackStart() { } void MeleeAttackEnd() { } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/03/29 04:20