unity 动态更新模型透明度

RaycastHit[] hits;

        Vector3 normal = transform.position - target.position;
hits = Physics.RaycastAll(target.position, normal, float.PositiveInfinity, mMask);
if (hits.Length>)
{
GameObject p = hits[].collider.gameObject;
if (p != null)
{ Debug.LogError("被碰撞的物体是:" + hits.Length);
SetMaterialsColor(p.GetComponent<Renderer>(), 0.5f);
}
}

注意mMask = 1<< LayerMask.NameToLayer("Wall");需要位运算

private void SetMaterialsColor(Renderer _renderer, float Transpa)
{
Material m = _renderer.sharedMaterial;
Color color = m.color;
color.a = Transpa;
m.SetColor("_Color",color);
}
上一篇:Android将应用log信息保存文件


下一篇:Python基础:五、Python程序的编写方式