/*/// <summary> * /// Returns all enemy hitboxes from given raycast hits. * /// </summary> * /// <param name="raycastHitsArg"></param> * /// <returns></returns> * private List<HitboxController> GetAllEnemyHitboxesFromRaycastHits(RaycastHit[] raycastHitsArg) * { * // initialize return var as dresh empty list * List<HitboxController> enemyHitboxes = new List<HitboxController>(); * * // initialize vars for upcoming loop * GameObject raycastHitObject; * HitboxController iterHitbox; * * // loop through all raycast hits * foreach (RaycastHit iterRayHit in raycastHitsArg) * { * // get the object of the iterating raycast hit * raycastHitObject = iterRayHit.transform.gameObject; * // if raycast hit an enemy object * if (raycastHitObject.CompareTag("Enemy")) * { * // get hitbox component of enemy that was hit * iterHitbox = raycastHitObject.GetComponent<HitboxController>(); * // if object hit was NOT an enemy hitbox * if (iterHitbox == null) * { * // skip to next loop iteration * continue; * } * * // add the enemy's hitbox to list * enemyHitboxes.Add(iterHitbox); * } * } * * // return populated list * return enemyHitboxes; * }*/ /// <summary> /// Interact with the interaction target. /// </summary> private void Interact() { // if have an interaction target if (interactTarget != null) { // interact with interaction target interactTarget.Interact(_characterMasterController); } }
void Update() { // Sækja hreyfiskipanir frá notanda moveX = Input.GetAxisRaw("Horizontal"); moveY = Input.GetAxisRaw("Vertical"); // Ef notandi ýtir á Interact-takkann, athuga hvort interactable hlutur sé innan seilingar if (Input.GetButtonDown("Interact")) { // Finna út í hvaða átt leikmaður snýr Direction currentDir = (Direction)animator.GetInteger("Direction"); Vector3 raycastDir = Vector3.zero; if (currentDir == Direction.Left) { raycastDir = Vector3.left; } else if (currentDir == Direction.Right) { raycastDir = Vector3.right; } else if (currentDir == Direction.Up) { raycastDir = Vector3.up; } else if (currentDir == Direction.Down) { raycastDir = Vector3.down; } // Raycast Vector3 raycastOrigin = new Vector3(transform.position.x + 0.5f, transform.position.y - 0.5f, transform.position.z); RaycastHit2D hit = Physics2D.Raycast(raycastOrigin, raycastDir, 1, colliderLayers); // Ef finnst interactable hlutur, kalla á Interact() aðferðina if (hit.collider != null && hit.collider.tag == "Interactable") { InteractableController interactable = hit.collider.GetComponent <InteractableController>(); interactable.Interact(); // Debug.Log("Player interacted with object " + interactable.ToString()); } } }
public virtual void Interact() { if (targetObject.tag == "Interactable") { InteractableController interactObject = targetObject.GetComponent <InteractableController>(); interactObject.Interact(gameObject); //if (targetObject.name == "Interactable") //{ // Debug.Log("Interacting"); // InteractableController interactObject = targetObject.GetComponent<InteractableController>(); // interactObject.Interact(gameObject); //} //else if (targetObject.name == "Person") //{ // Debug.Log("Interacting"); // InteractableController interactObject = targetObject.GetComponent<InteractableController>(); // interactObject.Interact(gameObject); //} } idle = true; }
private void DropSlotItem(Slot selectedSlot, Vector2 position) { foreach (Slot dropSlot in slots) { if (dropSlot != selectedSlot && dropSlot.Contains(position)) { inventoryController.SwapItems(selectedSlot, dropSlot); return; } } if (interactableController.CheckDropItemPosition(position)) { interactableController.Interact(); return; } Cell cell = stage.GetCellSafe(stage.WorldToTowerPoint(CameraController.Instance.Camera.ScreenToWorldPoint(position))); if (!inventoryController.DropOnCell(cell)) { inventoryController.DeselectSlot(); } }