【问题标题】:Toggle mesh renderer with a Unity event in Animator在 Animator 中使用 Unity 事件切换网格渲染器
【发布时间】:2021-10-06 01:54:05
【问题描述】:

大家好,我对 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# 问题标记为 Unityscript 问题。它们是不同的语言。

标签: c# unity3d


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-12-01
    • 2021-04-10
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多