Автор: Lumennes
При стандартных настройках игрок подбирает все предметы автоматически.
В этом уроке я вам покажу как подобрать предмет при наведении и нажатии клавиши.
Данный способ хорошо подходит для RPG игр.
для начало нам необходимо открыть класс ActionGameWindow.cs
Добавим новую переменную:
Item currentItem;
в метод UpdateCurrentPlayerUseObjects
нужно добавить...
//currentItem { Item overItem = null; Map.Instance.GetObjects(ray, delegate(MapObject obj, float scale) { Item item = obj as Item; if (item != null) { overItem = item; return false; } return true; }); //draw selection border if (overItem != null) { Bounds bounds = overItem.MapBounds; DrawObjectSelectionBorder(bounds); } if (overItem != currentItem) currentItem = overItem; }
Нужно изменить в том же методе.
этот код:
if (currentSwitch != null || currentSeeUnitAllowPlayerControl != null)
меняем на этот:
if (currentSwitch != null || currentItem != null || currentSeeUnitAllowPlayerControl != null)
В методе DrawTarget
этот код:
if( weapon != null || currentAttachedGuiObject != null || currentSwitch != null)
меняем на этот:
if( weapon != null || currentAttachedGuiObject != null || currentSwitch != null || currentItem != null)
И добавляем новый метод TakeItem
bool TakeItem() { if (currentItem == null) return false; currentItem.Take(GetPlayerUnit()); return true; }
В методе GameControlsManager_GameControlsEvent
добавляем:
if (TakeItem()) return;