internal void ItemButton(IUsable item, int m) { item.Drop(); if (m==0) item.Take(); else if (m==1) item.Use(); else item.Drop(); }
/// <summary> /// Processes the user input. /// </summary> private void ProcessActions() { // Handle take / drop action if (_controller.GetActionDown(PlayerAction.TakeDrop)) { // If we are holding an object if (_carriedObject != null) { OnObjectDropped?.Invoke(gameObject, this, _carriedObject); // Drop it! if (_carriedObject.Drop(gameObject)) { _carriedObject = null; } } else if (_data.trashCount > 0 && _data.closeWindows.Any()) { OnTrashThrown?.Invoke(gameObject, this, _data.trashCount); _data.trashCount = 0; GameObject t = Instantiate( GameHelper.GameManager.thrownTrash, transform.position + _data.closeWindows.First().transform.up * 2, Quaternion.identity); Destroy(t, 1); } // Else, get a new object if any available else if (_closeObjects.Any()) { // Find the closest object to the player _carriedObject = _closeObjects .Select(x => new { Obj = x, Distance = (x.Position - transform.position).magnitude }) .OrderBy(x => x.Obj.Priority) .ThenBy(x => x.Distance) .First().Obj; OnObjectTaken?.Invoke(gameObject, this, _carriedObject); if (!_carriedObject.Take(gameObject)) { _carriedObject = null; } } } // Handle use action if (_controller.GetActionDown(PlayerAction.Use) && _carriedObject != null) { _carriedObject.Use(gameObject); } }
internal void ItemButton(IUsable item, int m) { item.Drop(); if (m == 0) { item.Take(); } else if (m == 1) { item.Use(); } else { item.Drop(); } }