找回密码
 立即注册
查看: 3949|回复: 66

[脚本] 關於Animator的切換問題

[复制链接]
发表于 2017-6-2 23:11 | 显示全部楼层 |阅读模式

求助ˋ各位大神能幫幫我:"(
還是個Unity新手有很多不懂的地方請多多包涵
最近做了第一人稱加手部動畫的練習,
可是打入腳本後按鍵盤按鍵,手部動作還是沒反應
以下是我打的程式碼

[code=csharp]using UnityEngine;
using System.Collections;

public class onc : MonoBehaviour {
  public Animator Anim;
  int runningHash=Animator.StringToHash("running");
  int RunStateHash =Animator.StringToHash("Base Layer.Run");
  int weapononHash=Animator.StringToHash("weaponon");
  int IdleWithWeaponStateHash =Animator.StringToHash("Base Layer.IdleWithWeapon");
  int hit01Hash=Animator.StringToHash("hit01");
  int hit01StateHash =Animator.StringToHash("Base Layer.hit01");
  int hit02Hash=Animator.StringToHash("hit02");
  int hit2StateHash =Animator.StringToHash("Base Layer.hit2");
  public GameObject Torch;
  // Use this for initialization
  void Start () {
    Anim= GetComponent<Animator>();
  }
  
  // Update is called once per frame
  void Update () {
   
    AnimatorStateInfo stateInfo = Anim.GetCurrentAnimatorStateInfo(0);

    Anim.SetBool ("weaponon", false);
    Anim.SetBool ("running", false);
    Anim.SetBool ("hit01", false);
    Anim.SetBool ("hit02", false);
    if (Input.GetKeyDown (KeyCode.LeftShift))
    if (Input.GetKeyDown (KeyCode.LeftShift) && Input.GetKey (KeyCode.W) && stateInfo.fullPathHash==RunStateHash|| Input.GetKeyDown (KeyCode.LeftShift) && Input.GetKey (KeyCode.UpArrow)&&stateInfo.fullPathHash== RunStateHash) {  
      Anim.SetBool ("running", true);
    } else if (Input.GetKey (KeyCode.E) && stateInfo.fullPathHash == IdleWithWeaponStateHash) {
      Anim.SetBool ("weaponon", true);
    } else if (Input.GetKey (KeyCode.Z)&& stateInfo.fullPathHash== hit01StateHash) {
      Anim.SetBool ("hit01", true);
    } else if (Input.GetKey (KeyCode.X)&& stateInfo.fullPathHash== hit2StateHash) {
      Anim.SetBool ("hit02", true);
    }

    if(Input.GetKey (KeyCode.E))
    {
      GameObject Temp;
      Temp = (GameObject)Instantiate (Torch);
      Temp.SetActive (true);
    }

  }
}
[/code]

以及Animator,手臂放的位置

我把手臂骨骼動畫放在UNITY內建的第一人稱下面



想要做出按下Shift+前進可以撥放Run的動畫
還有按Z.X可以打擊(hit01.2動畫)
按E開始撥放IdleWithWeapon動畫時火把才會出現在手上

可以幫我看看哪裡出了問題嗎?
非常感謝~QWQ


 楼主| 发表于 2017-6-2 23:16 | 显示全部楼层

圖片出不來,我放在第二樓了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2017-6-24 12:11 | 显示全部楼层
很不错
发表于 2017-6-24 12:18 | 显示全部楼层
好帖就是要顶
发表于 2017-6-24 11:59 | 显示全部楼层
真心顶
发表于 2017-6-24 12:40 | 显示全部楼层
很好哦
发表于 2017-6-24 12:33 | 显示全部楼层
不错不错
发表于 2017-7-8 09:57 | 显示全部楼层
楼主是超人
发表于 2017-7-8 09:59 | 显示全部楼层
难得一见的好帖
发表于 2017-7-8 09:10 | 显示全部楼层
很好哦
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-27 12:41 , Processed in 0.137634 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表