7

在我的游戏中,如果玩家在游戏过程中与特定对象发生碰撞,我想通过在运行时编写脚本使玩家对象透明 2 秒……这可能吗?

4

4 回答 4

9

检查碰撞。当您想要的碰撞被触发时,您可以更改透明度。

GameObject g;

// 50% Transparency.
g.renderer.material.color.a = 0.5f; // a is the alpha value.

 // 100% Transparency.
g.renderer.material.color.a = 1.0f;

你可以这样做让你的程序等待时间:http ://docs.unity3d.com/Documentation/Manual/Coroutines.html

你会注意到这个例子正是你的问题。

于 2013-10-21T09:22:15.573 回答
5

试试这个扩展方法:

public static void ChangeAlpha(this Material mat, float alphaValue)
{
    Color oldColor = mat.color;
    Color newColor = new Color(oldColor.r, oldColor.g, oldColor.b, alphaValue);         
    mat.SetColor("_Color", newColor);               
}

然后,您可以通过以下方式调用它:

gameObject.renderer.material.ChangeAlpha( Your Alpha Value );
于 2013-10-21T17:41:08.027 回答
1

在 Unity 5 中,对我有用的最佳方法(使对象不可见)是在渲染模式下将所有我希望不可见的游戏对象的材质设置为透明。然后单击 albedo 旁边的小圆形按钮,然后向下滚动给定的项目列表,直到找到一个名为 UIMask 的项目。突出显示它并按 Enter。我是初学者,所以请问您是否需要更多说明。

*请注意,这是一个硬修复,我不确定您是否可以使用代码更改它。

**这是为滚动球的边界而设计的,包括球员跳跃功能。需要使墙壁不可见,但也需要能够碰撞以阻止空气产生的玩家对象

于 2016-07-12T13:18:10.227 回答
0

只需使用着色器即可完成,您可以在运行时快速有效地更改它

  • 创建新材质并将着色器设置为使用Unlit/Transparent Cutout
  • 分配您的游戏对象以使用此新材质
  • turn off all of the stuff in the mesh render of the game object: set cast shadows to off, receive shadows disabled, contribute to global illumination to disabled, turn off your light probes and reflections, set motion vectors to 'force no motion', turn off dynamic occlusion.
  • also don't forget to remove the mesh collider of the game object
于 2020-11-10T01:07:43.770 回答