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);
}