在层次结构中我有 2 ThirdPersonController。
在“窗口”>“动画器”中,我创建了新的空状态,将其称为“步行”并将其设置为“HumanoidWalk”,以便在运行游戏时两个玩家都在步行。
在其中一个上,我添加了脚本并将第二个 ThirdPersonController(1) 作为预制件。
然后,当运行游戏时,它会克隆 ThirdPersonController(1)。
所以我在层次结构中看到更多 N ThirdPersoncontrollers。
今天,为了更改每个 ThirdPersonController 的行走速度,我在检查器中更改了移动速度倍增器。
但是,如果我想在创建克隆时在脚本中设置彼此的速度,我该怎么办?
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 () {
}
}
我现在尝试的是获取预制件的 Animator 组件并设置所有克隆的速度:
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 上,我在“窗口”>“动画器”空状态中创建的原始控制器将其称为“Walk”并设置“HumandoidWalk”。
现在,由于某种原因设置速度,改变动画器速度不会产生任何影响,例如:
_animaotr.speed = 10;
仅当在 ThirdPersonController > Inspector > Third Person Character (Script) > Move Speed Multiplier 中更改速度时。它正在将相同的速度更改为层次结构中的所有 ThirdPerson 控制器,包括此 i 克隆。
但是我如何将每个克隆速度更改为另一个速度值?为什么 _ animator.speed 没有改变任何东西而我需要使用这个移动速度倍增器?