【问题标题】:Is there a way to change the alpha of the sprite of animation in unity 2d using script?有没有办法使用脚本在统一 2d 中更改动画精灵的 alpha?
【发布时间】:2018-10-08 12:06:58
【问题描述】:

我想让我的角色在某些情况下透明,我知道我可以通过

 GetComponent<SpriteRenderer>().color = new Color(1f,1f,1f,0.2f);

如果它是没有动画的单个精灵。

但问题是它是在动画期间,那么有什么办法可以通过脚本更改动画使用 alpha 的精灵表的 alpha 吗?

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您可以为 SpriteRenderer 的 Color 属性设置动画,只需更改关键帧中的 alpha。无论是单个精灵还是多个精灵,它都应该可以工作,因为您正在为渲染器的颜色设置动画。

    在动画窗口中点击添加属性 -> 展开 SpriteRenderer -> 选择颜色旁边的 +。

    【讨论】:

      【解决方案2】:

      我也无法在精灵动画期间更改精灵 alpha。但我终于想通了!

      不要更改 SpriteRenderer 的 color 属性,而是更改 material.color 属性:

      GetComponent<SpriteRenderer>().material.color = new Color(1f, 1f, 1f, 0.2f);
      

      【讨论】:

      • 谢谢你,正是我需要的。
      猜你喜欢
      • 2014-10-17
      • 1970-01-01
      • 2012-06-13
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      相关资源
      最近更新 更多