如何减少团结的不透明度? [英] How can I decrease opacity in unity?

查看:67
本文介绍了如何减少团结的不透明度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个主题堆积如山,但我认为它是错误的 使对象透明"以使其无法被看到并不是做事的最有效方法.您宁愿想做的就是在不想看到渲染器时使其处于非活动状态,而在看到渲染器时使其处于活动状态.

I see this subject in stack over flow but I think it is false Making an object 'transparent' so it cannot be seen is not the most efficient way to do things. What you rather want to do is make the renderer inactive when you don't want to see it, and active when you do.

如果在编辑器中单击gameObject,则应该有一个Mesh Renderer作为组件之一.

If you click on your gameObject in the editor, there should be a Mesh Renderer as one of the components.

要通过与此相同的gameObject附加的脚本将其设置为非活动状态,可以执行此操作...

To set it to inactive from a script attached to this same gameObject, you can do this...

gameObject.GetComponent<Renderer> ().enabled = false;

如果您真的想使用透明度,可以执行此操作...

If you really want to use transparency, you can do this...

gameObject.GetComponent<Renderer> ().material.color.a = 0;

尽管要设置透明度,但需要确保材质所使用的着色器支持透明度.我建议使用旧式"着色器/透明漫反射"着色器.

Although if you are setting transparency, you need to make sure the shader the material is using supports transparency. I would suggest using the Legacy Shaders/Transparent Diffuse shader.

我如何使用:

gameObject.GetComponent<Renderer> ().material.color.a = 0;

推荐答案

对于可能仍然遇到此问题的人来说,gameObject.GetComponent<Renderer> ().material.color不是变量.创建一个这样的变量:

For those who might still come across this question, gameObject.GetComponent<Renderer> ().material.color is not a variable. Create a variable as such:

var trans = 0.5f;
var col = gameObject.GetComponent<Renderer> ().material.color;

然后分配您的值:

col.a = trans;

还请注意,并非所有着色器都具有_Color属性.就我而言,我必须使用:

Also be aware that not all shaders have a _Color property. In my case, I had to use:

var col = gameObject.GetComponent<Renderer> ().material.GetColor("_TintColor");

这篇关于如何减少团结的不透明度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆