private void DoToggleDoor() { Vector3 dir = _currentTarget.transform.position - transform.position; Vector2 origin = transform.position + dir.normalized; bool onDoorIn = false; bool onDoorOut = false; Actuator actIn = null; Actuator actOut = null; RaycastHit2D[] hit = Physics2D.RaycastAll(origin, dir, 1f); Debug.DrawRay(new Vector3(origin.x, origin.y, 1f), dir, Color.green); for (int i = 0; i < hit.Length; i++) { GameObject go = hit[i].transform.gameObject; actIn = go.GetComponent <Actuator>(); if (actIn) { onDoorIn = true; break; } } origin = transform.position - dir.normalized; hit = Physics2D.RaycastAll(origin, -dir, 1f); for (int i = 0; i < hit.Length; i++) { GameObject go = hit[i].transform.gameObject; actOut = go.GetComponent <Actuator>(); if (actOut) { onDoorOut = true; break; } } if (onDoorIn && !actIn.GetToggled()) { actIn.OnAction(false); } else if (onDoorOut && actOut.GetToggled() && _animState == AnimState.Frightened) { actOut.OnAction(false); } if (onDoorOut || onDoorIn) { Color c = GetComponent <SpriteRenderer>().color; c.a = 0.5f; GetComponent <SpriteRenderer>().color = c; } else { Color c = GetComponent <SpriteRenderer>().color; c.a = 1f; GetComponent <SpriteRenderer>().color = c; } }