void Update() { #region Previous //First check if player is in visionDistance _currState = _player.gameObject.GetComponent <PlayerBehaviour>().State; if (Vector3.Distance(this.gameObject.transform.position, _player.position) <= _visionDistance) { //If Player is in VisionDistance -> Check if nothing is blocking LOS RaycastHit hit; if (Physics.Linecast(this.gameObject.transform.position, _player.position, out hit, _layerMask) || _currState == PlayerBehaviour.States.Sitting || _currState == PlayerBehaviour.States.KnockedOut) { //If the lineCast returns true, something is in between the player & AI if (this.gameObject.name.Contains("Type01")) { if (_aiBehaviour.IsAIFollowing) { _aiBehaviour.ResetAgent(); } } _aiBehaviour.IsAIFollowing = false; if (this.gameObject.name.Contains("Type02")) { //Doesn't happen _aiBehaviour.IsAILooking = false;; } //Reset Agent } else { //Check if following or looking type if (this.gameObject.name.Contains("Type01")) { _aiBehaviour.IsAIFollowing = true; } if (this.gameObject.name.Contains("Type02")) { _aiBehaviour.IsAILooking = true; } _aiBehaviour.PlayerPosition = _player.position; } } else { if (this.gameObject.name.Contains("Type01")) { _aiBehaviour.IsAIFollowing = false; } if (this.gameObject.name.Contains("Type02")) { _aiBehaviour.IsAILooking = false; } } #endregion }
private bool CheckLineOfSight(bool allowReset) { _currentState = _player.GetComponent <PlayerBehaviour>().State; RaycastHit hit; if (Physics.Linecast(this.gameObject.transform.position, _player.transform.position, out hit, _layerMask) || _currentState == PlayerBehaviour.States.Sitting || _currentState == PlayerBehaviour.States.KnockedOut) { //Something in between player & AI if (allowReset && _aiBehaviour.IsAIFollowing) { _aiBehaviour.ResetAgent(); } return(false); } else { _aiBehaviour.PlayerPosition = _player.transform.position; return(true); } }