我有一个对象,比如说一个ObjectBoy。我的目标在我点击地形后向前走,但它是先向后走,看起来是向后走。我在团结论坛上做过研究,为了克服这个问题,你必须把这个对象放在一个空的游戏对象中,作为它的父对象,并纠正它在孩子身上的方向。现在,一切都很好,除了动画不再播放,它只是漂浮在地形上去它的目的地。我正在考虑的解决方案是访问孩子的动画,但如果可能的话,我哪里也看不见。这是我的密码:
public class ClickToMove : MonoBehaviour {
NavMeshAgent navAgent;
Animation animation;
public AnimationClip runAnimation;
public AnimationClip idleAnimation;
void Start ()
{
navAgent = GetComponent<NavMeshAgent>();
animation = GetComponent<Animation>();
}
void Update ()
{
move();
animate();
}
void move()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButton(0))
{
if (Physics.Raycast(ray, out hit, 100))
{
navAgent.SetDestination(hit.point);
}
}
}
void animate()
{
if (navAgent.velocity.magnitude > 0.5f)
{
animation.CrossFade(runAnimation.name);
}
else
{
animation.CrossFade(idleAnimation.name);
}
}
}发布于 2015-07-18 15:02:25
您可以获得一个在带有GetComponentInChildren的子组件中的组件。
public Animation animation;
void Example() {
animation= GetComponentInChildren<Animation>();
}https://stackoverflow.com/questions/31492392
复制相似问题