iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1100107 碰到物體時讓物體變透明
by 黃國哲 2021-01-07 11:00:20, 回應(0), 人氣(449)

https://blog.csdn.net/weixin_44302602/article/details/103552552

private Color StartColor;
private void Start()
{
StartColor = BarraryObjecrt.GetComponent<Renderer>().material.color;//其中的BarraryObjecrt是墙体
}
 private void ProcessMode2()
    {
        transform.LookAt(Player.transform);
        transform.position = Player.transform.position + offset;
        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out hit, 1000))
        {
            if (hit.collider.tag == "Player")
            {
                isBall = true;
            }
            else
            {
                isBall = false;
            }
        }
        if (!isBall)
        {
            hit.collider.gameObject.GetComponent<Renderer>().material.color = new Color(1, 1, 1, 0.75f);
        }
        else if (isBall)
        {
            hit.collider.gameObject.GetComponent<Renderer>().material.color = StartColor;
        }

    }

回應