首页 > 解决方案 > 在 Animator 中使用 Unity 事件切换网格渲染器

问题描述

大家好,我对统一很陌生,我正在尝试制作一个动画,其中预制件中的一些网格仅在动画的中途出现。

我已经在 animator 中的所需时间添加了一个事件,但我无法确切知道我需要执行哪些代码来打开网格渲染器。

到目前为止,我有这个:

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

public class toggleMesh : MonoBehaviour
{
    public Renderer rend;
    // Start is called before the first frame update
    void Start()
    {
        rend = GetComponent<Renderer>();
        rend.enabled = false;
    }

    // Update is called once per frame
    public void toggleMeshR()
    {
        rend.enabled = true;
    }
}

对此的任何帮助将不胜感激

标签: c#unity3d

解决方案


如果您有您所说的动画,请在您希望调用toggleMeshR()的帧(时间)上放置一个动画事件。

当您右键单击动画时间轴时,您可以创建动画事件。更多信息:https ://docs.unity3d.com/Manual/script-AnimationWindowEvent.html


推荐阅读