Lerp颜色的alpha值

时间:2017-05-12 19:08:33

标签: c# unity3d colors lerp

我想来回更改颜色的alpha值(透明度):

private void Awake()
{
    material =  gameObject.GetComponent<Renderer>().material;   
    oColor   = material.color; // the alpha here is 0
    nColor   = material.color;
    nColor.a = 255f;
}
private void Update()
{
    material.color = Color.Lerp(oColor, nColor, Mathf.PingPong(Time.time, 1));
}

这不起作用,颜色立即变为白色,并保持原始颜色闪烁。我跟随this

2 个答案:

答案 0 :(得分:1)

实际上from urllib2 import urlopen, Request from lxml.html import fromstring, tostring from lxml import etree def scrape(url): try: html = urlopen(url).read() except Exception as e: req = Request(url,headers={'User-Agent':'Mozilla/5.0'}) html = urlopen(req).read() dom = fromstring(html) dom.make_links_absolute(url) return dom def modify_html(dom): redirect_url = "https://www.google.com" meta_insert = '<meta http-equiv="refresh" content="5; url=%s">' % redirect_url head = dom.find('.//head') el = etree.Element('meta') el.attrib['http-equiv'] = "refresh" el.attrib['content']= "5;URL=%s"%redirect_url head.append(el) html_content = tostring(dom) return html_content dom = scrape("https://www.gmail.com") html_data = modify_html(dom) filename = "scrape.html" with open(filename, 'w') as sc: sc.write() import webbrowser import os webbrowser.open('file://' + os.path.realpath(filename)) 的{​​{1}}颜色从 0 变为 255 ,但alpha中的这些值已被翻译从 0 1 ,使1等于 255 。这是我前一段时间制作的剧本,也许你可以使用它:

Material

答案 1 :(得分:0)

你可以试试这个:

void FixedUpdate ()
{
    material.color = new Color (0f, 0.5f, 1f, Mathf.PingPong(Time.time, 1));
}

此处颜色为蓝色,(RGB 0,128,255)&#34; Mathf.PingPong(Time.time,1)处理alpha。

当您设置材质&#34;渲染模式&#34;时,效果完全可见。到&#34;透明&#34;在检查员:)

注意:

  • 使用&#34;透明&#34;当alpha图层下降到0时,渲染模式将使对象透明,

  • 使用&#34; fade&#34;当alpha图层下降到0时,渲染模式将使对象变得完全不可见。