Created
June 18, 2019 06:41
-
-
Save gkagm2/63e9d681809214eaa4ea48b110879464 to your computer and use it in GitHub Desktop.
aniamtor에서 animation의 length 설정,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class UnityChanController06 : MonoBehaviour { | |
// parameters | |
public int speed; | |
// animator hash | |
int dirForwardHash = Animator.StringToHash("Dir_Forward"); | |
int moveHash = Animator.StringToHash("Move"); | |
float timeOfAnimation; | |
// references | |
Animator anim; | |
CharacterController characterController; | |
// Use this for initialization | |
void Start() | |
{ | |
anim = GetComponent<Animator>(); | |
characterController = GetComponent<CharacterController>(); | |
timeOfAnimation = GetComponent<Animator>().runtimeAnimatorController.animationClips[0].length; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if (Input.GetKey(KeyCode.Q)) | |
{ | |
anim.SetTrigger("Attack"); | |
if (anim.GetCurrentAnimatorStateInfo(1).IsName("Punch") || anim.GetCurrentAnimatorStateInfo(1).normalizedTime == 0.5f) | |
{ | |
anim.Play("Punch", 1, 0.5f); | |
//anim.SetFloat("normalizedTime", 0.5f); | |
} | |
} | |
else | |
{ | |
anim.ResetTrigger("Attack"); | |
if (anim.GetCurrentAnimatorStateInfo(1).IsName("Punch")) | |
{ | |
//anim.SetFloat("spsped", 1f); | |
} | |
} | |
float dir_f = Input.GetAxis("Vertical"); // f : forward | |
Debug.Log("dir_f : " + dir_f); | |
if (dir_f != 0) // move | |
{ | |
anim.SetBool(moveHash, true); | |
anim.SetFloat(dirForwardHash, dir_f); | |
} | |
else | |
{ // just stand | |
anim.SetBool(moveHash, false); | |
} | |
// Movement | |
characterController.Move(new Vector3(0, 0, dir_f * speed * Time.deltaTime)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment