前一篇文章Unity程式設計初體驗(七)-操縱人物模型的程式設計中,左上角有原來程式提供的2D選項表單,這次我們試著把它拿掉,並設計一個全新的程式來操縱人物模型。
1.撰寫下列程式(PlayZombie.cs)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayZombie : MonoBehaviour {
public Transform[] transforms;
private Animator[] animator;
private string currentState = "";
private int state = 0;
private int timecnt = 100;
// Use this for initialization
void Start () {
animator = new Animator[transforms.Length];
for (int i = 0; i < transforms.Length; i++)
{
animator[i] = transforms[i].GetComponent
}
for (int j = 0; j < animator.Length; j++)
{
//animator[j].SetBool("idle0ToIdle0", false);
animator[j].SetBool("idle0ToIdle1", false);
animator[j].SetBool("idle0ToWalk", false);
animator[j].SetBool("idle0ToRun", false);
animator[j].SetBool("idle0ToWound", false);
//animator[j].SetBool("idle0ToSkill1", false);
animator[j].SetBool("idle0ToSkill0", false);
animator[j].SetBool("idle0ToAttack1", false);
animator[j].SetBool("idle0ToAttack0", false);
animator[j].SetBool("idle0ToDeath", false);
}
}
// Update is called once per frame
void Update () {
AnimatorStateInfo stateInfo = animator[0].GetCurrentAnimatorStateInfo(0);
if (!stateInfo.IsName("Base Layer.idle0"))
{
for (int j = 0; j < animator.Length; j++)
{
//animator[j].SetBool("idle0ToIdle0", false);
animator[j].SetBool("idle0ToIdle1", false);
animator[j].SetBool("idle0ToWalk", false);
animator[j].SetBool("idle0ToRun", false);
animator[j].SetBool("idle0ToWound", false);
//animator[j].SetBool("idle0ToSkill1", false);
animator[j].SetBool("idle0ToSkill0", false);
animator[j].SetBool("idle0ToAttack1", false);
animator[j].SetBool("idle0ToAttack0", false);
animator[j].SetBool("idle0ToDeath", false);
}
}
else
{
for (int j = 0; j < animator.Length; j++)
{
animator[j].SetBool("walkToIdle0", false);
animator[j].SetBool("runToIdle0", false);
animator[j].SetBool("deathToIdle0", false);
}
}
timecnt = timecnt - 1;
if (timecnt <0 p=""> {
timecnt = 0;
switch (state)
{
case 0:
for (int j = 0; j < animator.Length; j++)
{
animator[j].SetBool("idle0ToAttack0", false);
animator[j].SetBool("idle0ToRun", false);
}
Debug.Log("state 0");
state = 1;
timecnt = 100;
break;
case 1:
for (int j = 0; j < animator.Length; j++)
{
animator[j].SetBool("idle0ToAttack1", true);
}
Debug.Log("state 1");
state = 2;
timecnt = 300;
break;
case 2:
for (int j = 0; j < animator.Length; j++)
{
animator[j].SetBool("idle0ToAttack0", true);
}
Debug.Log("state 2");
state = 0;
timecnt = 500;
break;
default:
break;
}
}
}
}
0>
全英文介面,使用上會花上不少時間去習慣
回覆刪除多看一些英文介面,久了就習慣。
刪除敏哥,請問為什麼從vuforia下載下來的五顆星圖片在Unity顯示不出來呢?
回覆刪除我有空試試看
刪除需要花點時間了解程式原理及解說
回覆刪除那是一定的
刪除請問如何在已經完成的建模上面再做新增物件呢?
回覆刪除這是個好問題
刪除我們所設計的網頁都能輕鬆改變我們的生活[作品]求~好看的動漫
回覆刪除很棒!
刪除我們所設計的網頁
回覆刪除什麼網頁?
刪除