unity 動態更新模型透明度
阿新 • • 發佈:2019-01-12
RaycastHit[] hits; Vector3 normal = transform.position - target.position; hits = Physics.RaycastAll(target.position, normal, float.PositiveInfinity, mMask); if (hits.Length>0) { GameObject p = hits[0].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); }