public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial) { if (forceHidden) { // ensure player can still see themself var uv = GetComponent<NetworkIdentity>(); if (uv.connectionToClient != null) { observers.Add(uv.connectionToClient); } return true; }
// find players within range switch (checkMethod) { case CheckMethod.Physics3D: { var hits = Physics.OverlapSphere(transform.position, visRange); foreach (var hit in hits) { // (if an object has a connectionToClient, it is a player) //var uv = hit.GetComponent<NetworkIdentity>(); // < -----DEFAULT var uv = hit.GetComponentInParent<NetworkIdentity>(); // <----- MODIFIED if (uv != null && uv.connectionToClient != null) { observers.Add(uv.connectionToClient); } } return true; } case CheckMethod.Physics2D: { var hits = Physics2D.OverlapCircleAll(transform.position, visRange); foreach (var hit in hits) { // (if an object has a connectionToClient, it is a player) //var uv = hit.GetComponent<NetworkIdentity>(); // < -----DEFAULT var uv = hit.GetComponentInParent<NetworkIdentity>(); // <----- MODIFIED if (uv != null && uv.connectionToClient != null) { observers.Add(uv.connectionToClient); } } return true; } } return false; }
相对于源码只改了一行代码就是 var uv = hit.GetComponent<NetworkIdentity>(); 改为 var uv = hit.GetComponentInParent<NetworkIdentity>();