-
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
- 2022.03.28 Monday
- ¥¹¥Ý¥ó¥µ¡¼¥µ¥¤¥È
-
°ìÄê´ü´Ö¹¹¿·¤¬¤Ê¤¤¤¿¤á¹¹ð¤òɽ¼¨¤·¤Æ¤¤¤Þ¤¹
- | ¥¹¥Ý¥ó¥µ¡¼¥É¥ê¥ó¥¯ | - | | - | - | pookmark |
-
¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
- 2014.12.31 Wednesday
- Mecanim Tutorial ¤Î¥¹¥¯¥ê¥×¥È¤òAnimaterÀ©¸æ¥¹¥¯¥ê¥×¥È¤òÍý²ò¤Ë¤Ä¤È¤á¤Æ¤ß¤¿¡£
-
Mecanim Tutorial ¤Î¥¹¥¯¥ê¥×¥È¤òAnimaterÀ©¸æ¥¹¥¯¥ê¥×¥È¤òÍý²ò¤Ë¤Ä¤È¤á¤Æ¤ß¤¿¡£
http://www.mediafire.com/download/1fhhzdx9gu2ahdw/MecanimTute.zip
using UnityEngine;
using System.Collections;
// Require these components when using this script
[RequireComponent(typeof (Animator))]
[RequireComponent(typeof (CapsuleCollider))]
[RequireComponent(typeof (Rigidbody))]
public class BotControlScript : MonoBehaviour
{
[System.NonSerialized]
public float lookWeight; // the amount to transition when using head look
[System.NonSerialized]
public Transform enemy; // a transform to Lerp the camera to during head look
public float animSpeed = 1.5f; // a public setting for overall animator animation speed
public float lookSmoother = 3f; // a smoothing setting for camera motion
public bool useCurves; // a setting for teaching purposes to show use of curves
private Animator anim; // a reference to the animator on the character
private AnimatorStateInfo currentBaseState; // a reference to the current state of the animator, used for base layer
private AnimatorStateInfo layer2CurrentState; // a reference to the current state of the animator, used for layer 2
private CapsuleCollider col; // a reference to the capsule collider of the character
static int idleState = Animator.StringToHash("Base Layer.Idle");
static int locoState = Animator.StringToHash("Base Layer.Locomotion"); // these integers are references to our animator's states
static int jumpState = Animator.StringToHash("Base Layer.Jump"); // and are used to check state for various actions to occur
static int jumpDownState = Animator.StringToHash("Base Layer.JumpDown"); // within our FixedUpdate() function below
static int fallState = Animator.StringToHash("Base Layer.Fall");
static int rollState = Animator.StringToHash("Base Layer.Roll");
static int waveState = Animator.StringToHash("Layer2.Wave");
void Start ()
{
// initialising reference variables
anim = GetComponent<Animator>();
col = GetComponent<CapsuleCollider>();
enemy = GameObject.Find("Enemy").transform;
if(anim.layerCount ==2)
anim.SetLayerWeight(1, 1);
}
void FixedUpdate ()
{
float h = Input.GetAxis("Horizontal"); // setup h variable as our horizontal input axis
float v = Input.GetAxis("Vertical"); // setup v variables as our vertical input axis
anim.SetFloat("Speed", v); // set our animator's float parameter 'Speed' equal to the vertical input axis
anim.SetFloat("Direction", h); // set our animator's float parameter 'Direction' equal to the horizontal input axis
anim.speed = animSpeed; // set the speed of our animator to the public variable 'animSpeed'
anim.SetLookAtWeight(lookWeight); // set the Look At Weight - amount to use look at IK vs using the head's animation
currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // set our currentState variable to the current state of the Base Layer (0) of animation
if(anim.layerCount ==2)
layer2CurrentState = anim.GetCurrentAnimatorStateInfo(1); // set our layer2CurrentState variable to the current state of the second Layer (1) of animation
// LOOK AT ENEMY
// if we hold Alt..
if(Input.GetButton("Fire2"))
{
// ...set a position to look at with the head, and use Lerp to smooth the look weight from animation to IK (see line 54)
anim.SetLookAtPosition(enemy.position);
lookWeight = Mathf.Lerp(lookWeight,1f,Time.deltaTime*lookSmoother);
}
// else, return to using animation for the head by lerping back to 0 for look at weight
else
{
lookWeight = Mathf.Lerp(lookWeight,0f,Time.deltaTime*lookSmoother);
}
// STANDARD JUMPING
// if we are currently in a state called Locomotion (see line 25), then