【发布时间】:2016-06-27 19:22:10
【问题描述】:
我正在尝试为生成的平台预制件设置动画(平台对象本身在一个空的范围内,因为它的位置发生了变化)当 Runner 对象与它碰撞时(onCollisonEnter)向下,在碰撞退出时向上。
我已经逐字遵循了对我的旧问题的回答-Unity, C# - cannot make object move down from current y position ONCE on collision enter?,但是尽管按照指示在我的动画师中使用了这个,但我无法使用动画师来制作动画:
一位回答的人建议我使用 Lerp 完全使用代码为平台预制件制作动画。我研究了 Lerp,但由于我需要 2 个单独的状态来表示 Down/Idle Down(使平台保持关闭状态),而 up/idle up 也需要两种不同的状态,所以我不知道该怎么做。
如何以编程方式使用 Lerp 实现此效果?能不能达到我想要的效果?
错误:
编辑:
我如何生成(出队然后入队)我的平台:
nextPosition += new Vector3 (
Random.Range (minGap.x, maxGap.x) + scale.x,
Random.Range (minGap.y, maxGap.y),
Random.Range (minGap.z, maxGap.z));
Transform o = objectQueue.Dequeue();
o.localScale = scale;
o.localPosition = position;
//o.localEulerAngles = rotation;
o.gameObject.SetActive (true);
int materialIndex = Random.Range(0, materials.Length);
o.GetComponent<Renderer>().material = materials[materialIndex];
o.GetComponent<Collider> ().material = noFrictionMaterial;
platform newScript = new o.GetComponent<platform>(); //getting an error here when I tried to implement your code
objectQueue.Enqueue (o);
if(nextPosition.y < minY){
nextPosition.y = minY + maxGap.y;
}
else if(nextPosition.y > maxY){
nextPosition.y = maxY - maxGap.y;
}
这就是向量应该始终是什么,也是我最初在 start() 中设置的:
up = new Vector3 (transform.position.x, transform.position.y, transform.position.z);
down = new Vector3 (transform.position.x, transform.position.y-2f, transform.position.z);
由于平台实际上并未生成,您确定这是错误吗?你能帮帮我吗?
【问题讨论】:
-
只用
Lerp上下浮动?例如,上下跳跃。最好确切地知道您要做什么。