private void FieldOfViewCheck() { Collider[] rangeChecks = Physics.OverlapSphere(characterList.GetTransformCurrentCharacter().position, radius, targetMask); canSee = false; visibleTargets.Clear(); for (int i = 0; rangeChecks.Length != 0 && i < rangeChecks.Length; i++) { Transform target = rangeChecks[i].transform; Vector3 directionToTarget = (target.position - characterList.GetTransformCurrentCharacter().position).normalized; float distanceToTarget = Vector3.Distance(characterList.GetTransformCurrentCharacter().position, target.position); if (!Physics.Raycast(characterList.GetTransformCurrentCharacter().position, directionToTarget, distanceToTarget, obstacleMask)) { Debug.DrawRay(characterList.GetTransformCurrentCharacter().position, target.position.normalized, Color.green, 1); visibleTargets.Add(target); //print("YES"); canSee = true; } } }
// Update is called once per frame void Update() { GameObject theCharacter = GameObject.Find("GridMovement"); GridMovement characters = theCharacter.GetComponent <GridMovement>(); Ray r = new Ray(transform.position, characters.GetTransformCurrentCharacter().position - transform.position); RaycastHit hit; if (Physics.Raycast(r, out hit, 1000, fogLayer, QueryTriggerInteraction.Collide)) { for (int i = 0; i < vertices.Length; i++) { Vector3 v = fogOfWarPlane.transform.TransformPoint(vertices[i]); float dist = Vector3.SqrMagnitude(v - hit.point); if (dist < radiusSqr) { float alpha = Mathf.Min(colors[i].a, dist / radiusSqr); colors[i].a = alpha; } } UpdateColor(); } }