首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >改变透明纹理的不透明度

改变透明纹理的不透明度
EN

Stack Overflow用户
提问于 2016-06-15 13:13:44
回答 1查看 77关注 0票数 0

我有一个透明的质感链连接栅栏。我希望当球员从z方向靠近时,栅栏会逐渐消失。我的问题是,由于栅栏是透明的,不透明滑块消失并使用图像透明度。(我希望透明纹理淡入)我的当前代码:

代码语言:javascript
复制
public class WallFader : MonoBehaviour {


public GameObject wallone;

private Vector3 wallonetransform;

private Color wallonecolor;


public GameObject player;
private Vector3 playerposition;

private float PPX;
private float PPZ;

// Use this for initialization
void Start()

{
    wallonetransform = wallone.GetComponent<Transform>().position;
    wallonecolor = wallone.GetComponent<Renderer>().material.color;

}

// Update is called once per frame
void Update () {


    playerposition = player.transform.position;
    PPX = playerposition.x;
    PPZ = playerposition.z;

    // Distance to the large flat wall
    float wallonedist = wallonetransform.z - PPZ;

    if (wallonedist > 10)
    {
        wallonecolor.a = 0;
    }

    else
    {
        //fade in script
    }

  }

当壁虎> 10时,篱笆永不褪色或消失。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-15 13:17:22

Color是一个struct,这意味着更改它不会改变Renderer的实例。它是来自colorRenderer的副本。如果更改颜色,则必须将整个颜色重新分配回Renderer以使其生效。

代码语言:javascript
复制
public class WallFader : MonoBehaviour
{
    public GameObject wallone;

    private Vector3 wallonetransform;

    private Color wallonecolor;
    Renderer renderer;

    public GameObject player;
    private Vector3 playerposition;

    private float PPX;
    private float PPZ;

    // Use this for initialization
    void Start()
    {
        wallonetransform = wallone.GetComponent<Transform>().position;
        renderer = wallone.GetComponent<Renderer>();
        wallonecolor = wallone.GetComponent<Renderer>().material.color;
    }

    // Update is called once per frame
    void Update()
    {


        playerposition = player.transform.position;
        PPX = playerposition.x;
        PPZ = playerposition.z;

        // Distance to the large flat wall
        float wallonedist = wallonetransform.z - PPZ;

        if (wallonedist > 10)
        {
            wallonecolor.a = 0;
            renderer.material.color = wallonecolor; //Apply the color
        }

        else
        {
            //fade in script
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37836524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档