/// <summary> /// Start is called before the first frame update, this handles the initialization of the player /// </summary> void Start() { _myTransform = this.transform; _collectablesInRange = new List <GameObject>(); _myItems = new List <Item>(); _currentInteractState = PlayerInteractState.Collecting; currencies = new int[5]; }
/// <summary> /// Toggles between the Browsing and Talking states based on the obj variable, called by /// the StoreManager via GameObserverManager /// </summary> /// <param name="obj">Defines if the player is Browsing or Talking</param> private void OnBrowsingToggle(bool obj) { if (obj) { _currentInteractState = PlayerInteractState.Browsing; } else { _currentInteractState = PlayerInteractState.Talking; } }
/// <summary> /// Checks for the closest Talkable NPC in range using a CircleCast based on collectRange, if it finds one, /// then it sets it to the _talkableInRange variable, next a check is done to see if the NPC is still in range /// and if it is its Talk Icon is enabled and the Player Interact state is changed to Talking. /// </summary> private void CheckTalkableInRange() { // CircleCast to find the closest talkable NPC in range RaycastHit2D talkable = Physics2D.CircleCast((Vector2)transform.position, collectRange, Vector2.zero, 0, _npcLayerMask); if (talkable) { GameObject npcGO = talkable.transform.gameObject; if (ReferenceEquals(_talkableInRange, null) || _talkableInRange != npcGO) { _talkableInRange = npcGO; } } // if there's a talkable NPC in range, then check if its active and its distance to the player // if it fails, return to the Collecting state, else go to the Talking state. Also toggle the // talk icon. if (!ReferenceEquals(_talkableInRange, null)) { if (!_talkableInRange.activeSelf) { _talkableInRange = null; _currentInteractState = PlayerInteractState.Collecting; } else { if (Vector3.Distance(transform.position, _talkableInRange.transform.position) > collectRange) { _talkableInRange.GetComponent <ITalkable>().ToggleTalkIcon(false); _talkableInRange = null; _currentInteractState = PlayerInteractState.Collecting; } else { _talkableInRange.GetComponent <ITalkable>().ToggleTalkIcon(true); _currentInteractState = PlayerInteractState.Talking; ToggleAllCollectIcons(false); } } } }