在層次結構中,我有2個ThirdPersonController。 在Window> Animator中,我創建了一個名爲Walk的新空狀態,並將其設置爲HumanoidWalk,這樣在運行遊戲時兩個玩家都在走路。我如何更改每個gameobject移動速度?
在其中之一,我添加了腳本和作爲預製第二ThirdPersonController(1)。
然後當運行遊戲時,它會製作ThirdPersonController(1)的克隆。 所以我在Hierarchy中看到更多的N ThirdPersoncontrollers。
今天要改變每個ThirdPersonController的行走速度,我在Inspector中改變了移動速度乘數。 但是如果我想在創建克隆時爲腳本創建另一個速度,我該怎麼做呢?
using UnityEngine;
using System.Collections;
public class Multiple_objects : MonoBehaviour {
public GameObject prefab;
public GameObject[] gos;
public int NumberOfObjects;
void Awake()
{
gos = new GameObject[NumberOfObjects];
for(int i = 0; i < gos.Length; i++)
{
GameObject clone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
gos [i] = clone;
}
}
// Use this for initialization
void Start() {
}
// Update is called once per frame
void Update() {
}
}
我現在嘗試是獲得預製的動畫組件和速度設置爲所有克隆:
using UnityEngine;
using System.Collections;
public class Multiple_objects : MonoBehaviour {
public GameObject prefab;
public GameObject[] gos;
public int NumberOfObjects;
private Animator _animaotr;
void Awake()
{
gos = new GameObject[NumberOfObjects];
for(int i = 0; i < gos.Length; i++)
{
GameObject clone = (GameObject)Instantiate(prefab, Vector3.zero, Quaternion.identity);
gos [i] = clone;
_animaotr.speed = 10;
}
}
// Use this for initialization
void Start() {
_animaotr = prefab.GetComponent<Animator>();
}
// Update is called once per frame
void Update() {
}
}
但主要的問題是,我在層級第一ThirdPersonController的原創的一個我在Window> Animator空狀態中創建,稱爲Walk並設置了HumandoidWalk。
我們設定的速度由於某種原因,改變動畫速度的東西,例如從未效果:
在ThirdPersonController>檢查>第三人稱角色(腳本)改變速度_animaotr.speed = 10;
只有當>移動速度乘數。它正在改變層次中所有ThirdPerson控制器的速度,包括這個我的克隆。
但是,我如何將每個克隆速度更改爲速度的另一個速度?爲什麼_animator.speed沒有改變任何東西,我需要使用這個移動速度倍增器?
屬性m_MoveSpeedMultiplier不存在。 –
@TheLostLostit請再次閱讀說明。 **「在運行時訪問它,你必須在'ThirdPersonCharacter'腳本中將'float m_MoveSpeedMultiplier = 1f;'更改爲'public float m_MoveSpeedMultiplier = 1f;'。」** – Programmer