Unity动画事件没有接收器。

4
以下是我收到的两个错误信息。似乎只有在运行动画时才会出现这种情况。希望能得到帮助。我正在为安卓构建此游戏,并使用鼠标点击来移动角色。由于鼠标点击会转换为触摸事件,因此据我所知,这对游戏没有任何影响。我想我还应该注意到,游戏播放时动画效果很好。
'defaultModelfbx' AnimationEvent 'FootL' has no receiver! Are you missing a component?

'defaultModelfbx' AnimationEvent 'FootR' has no receiver! Are you missing a component?

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlayerController : MonoBehaviour
{
    float speed = 10;
    float rotSpeed = 5;
    Vector3 targetPosition;
    Vector3 lookAtTarget;
    Quaternion playerRot;
    bool moving = false;
    Animator thisAnim;


    void Update()
    {
        thisAnim = GetComponent<Animator>();
        // Get movement of the finger since last frame
        if (Input.GetMouseButton(0))
        {
           SetTargetPosition();
        }

        if (moving)
        {
            Move();
        }
    }

    void SetTargetPosition()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if(Physics.Raycast(ray, out hit, 1000))
        {

            targetPosition = hit.point;
            lookAtTarget = new Vector3(targetPosition.x - `transform.position.x, 0, targetPosition.z - transform.position.z);`
            playerRot = Quaternion.LookRotation(lookAtTarget);
            moving = true;
        }

    }

    void Move()
    {
        thisAnim.SetFloat("speed", 1);
        transform.rotation = Quaternion.Slerp(transform.rotation, playerRot, rotSpeed * Time.deltaTime);

        transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);

        if (transform.position == targetPosition)
        {
            moving = false;
            thisAnim.SetFloat("speed", 0);
        }
    }
}

AnimationEvent Error


1
你的动画上有任何事件吗?就像时间轴上的一个小白色图钉:AnimationEvents - Nathalia Soragge
非常感谢,我已经找到了这两个事件。 - James Leshko
是的,请添加您自己的答案。我相信您可以添加更多细节,以创建所需的事件函数。 - James Leshko
1
你的回答很好,我没有更多可以补充的了!我认为对于那些有同样问题的人来说已经足够了 (: - Nathalia Soragge
4个回答

3

我也曾遇到同样的错误,但是原因和解决方案不同。

我的所有代码都在一个(祖先)游戏对象中(例如,WerewolfPlayer),而我想保持这种方式。动画师位于一个(祖先)子游戏对象中(例如,WEREWOLF_PBR),但它找不到动画事件: enter image description here

为了解决这个问题,我将子游戏对象中的事件冒泡到父游戏对象中:

enter image description here

我编辑了父游戏对象(e.g. WerewolfPlayer)中的PlayerController.cs文件,找到新的“手动传递动画事件”脚本,并在发生事件时触发动画事件:

using UnityEngine;
using System;

public class PlayerController : MonoBehaviour
{
    private HandOffAnimationEvent handOffAnimationEvent;

    // called when animation event fires
    public void Pickup()
    {
        Debug.Log("player picks up object here...");
    }

    void OnEnable()
    {
        handOffAnimationEvent = GetComponentInChildren<HandOffAnimationEvent>();
        handOffAnimationEvent.OnPickup += Pickup;
    }

    void OnDisable()
    {
        handOffAnimationEvent.OnPickup -= Pickup;
    }
}

新的HandOffAnimationEvents.cs文件被添加到子游戏对象(例如WEREWOLF_PBR),当动画事件触发时,它会触发自己的事件。
using UnityEngine;
using System;

public class HandOffAnimationEvent : MonoBehaviour
{
    public event Action OnPickup;

    // This is the animation event, defined/called by animation
    public void Pickup()
    {
        OnPickup?.Invoke();
    }
}

1
好的,感谢Nathalia Soragge,我已经找到了解决问题的方法。 如果你仔细看动画窗口,你会发现时间轴顶部有两个白色的破折号。我在图片上点击了其中一个,果然它是导致错误信息的事件之一。 我认为我可以删除这两个事件,因为我在代码中没有它们。在这种情况下,它正在寻找我的PlayerController中的事件,因为它附加到我的Model defaultModelfbx。 更新:我已经删除了这两个事件,现在一切都运行得很顺利。再次感谢Nathalia!!!;)

Events Found


1
没问题,很高兴能帮忙! - Nathalia Soragge

1

0

我曾经遇到过同样的问题。我通过删除所有动画事件并重新创建它们来解决了这个问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接