//------------------This script it's own methods-------------------------// private void PerformPlayerRecievedAnItem(BlockInfo blockInfo) { //this method will get the current item that the player get //and push the things inside to the inventory or the hotbar slot //we dont need to check if this block info has a block inside or not..(cuz it already checked) //hotbar slot first if (!PlayerInventoryController.Instance.CheckIsHotBarSlotsFull()) { //made for the hot bar slots PlayerHotBarSlotController thisCurrentEmptyHotBarSlotController = PlayerInventoryController.Instance.GetFirstSameItemButNotFullHotBarSlot(blockInfo); if (thisCurrentEmptyHotBarSlotController != null) { thisCurrentEmptyHotBarSlotController.slotInfoContainer.currentItems++; thisCurrentEmptyHotBarSlotController.UpdateCountText(); } else { thisCurrentEmptyHotBarSlotController = PlayerInventoryController.Instance.GetLastEmptySlotPlayerHotBarSlotController(); thisCurrentEmptyHotBarSlotController.slotInfoContainer.currentItems = 1; thisCurrentEmptyHotBarSlotController.slotInfoContainer.blockInfo = blockInfo; thisCurrentEmptyHotBarSlotController.UpdateAllDisplay(); } thisCurrentEmptyHotBarSlotController.slotInfoContainer.blockInfo = blockInfo; thisCurrentEmptyHotBarSlotController.UpdateIMGDisplay(); } //inventory last else if (!PlayerInventoryController.Instance.CheckIsInventorySlotsFull()) { //made for the inventory slots PlayerInventorySlotController thisCurrentEmptyInventorySlotController = PlayerInventoryController.Instance.GetFirstSameItemButNotFullInventorySlot(blockInfo); if (thisCurrentEmptyInventorySlotController != null) { thisCurrentEmptyInventorySlotController.currentItems++; thisCurrentEmptyInventorySlotController.UpdateCountText(); } else { thisCurrentEmptyInventorySlotController = PlayerInventoryController.Instance.GetLastEmptySlotPlayerInventoryController(); thisCurrentEmptyInventorySlotController.currentItems = 1; thisCurrentEmptyInventorySlotController.blockInfo = blockInfo; thisCurrentEmptyInventorySlotController.UpdateAllDisplay(); } } else { Debug.Log("Player Inventory / hotbar slot already full!"); } }
//-----------------------------------fuction methods---------------------------// private void PlayerPlaceBlockAtPointingDir(BlockInfo blockInfo) { //then ray cast on the block Vector2 playerPointingDir = GetPlayerPointingDir(); RaycastHit2D raycastHit2D = GetRayCastHitAtPlayerLooking(); if (raycastHit2D != new RaycastHit2D()) { //we will use the block grid later BlockGridController blockGridController = BlockGridController.Instance; //calculate Vector2 hittedBlockPos = raycastHit2D.transform.position; Vector2 DiffOfBlockAndPoint = hittedBlockPos - raycastHit2D.point; //then get the position of the block's position Vector2 colliderPos = raycastHit2D.collider.transform.position; //then check the length from the player to the block Vector2 diffFromPlayerToPointedBlock = hittedBlockPos - (Vector2)transform.position; //check if the player's pos to the block's pos's length if (diffFromPlayerToPointedBlock.magnitude > transform.localScale.magnitude * 0.75f) { bool placedBlock = false; //check for placed place //left if (DiffOfBlockAndPoint.x >= 0.5f) { blockGridController.SetBlock(blockGridController.FindGamePosWithSceneVector(colliderPos - Vector2.right), blockInfo); placedBlock = true; if (isDebugging) { Debug.Log("left"); } } //right else if (DiffOfBlockAndPoint.x <= -0.5f) { blockGridController.SetBlock(blockGridController.FindGamePosWithSceneVector(colliderPos + Vector2.right), blockInfo); placedBlock = true; if (isDebugging) { Debug.Log("Right"); } } //dpwn else if (DiffOfBlockAndPoint.y >= 0.5f) { blockGridController.SetBlock(blockGridController.FindGamePosWithSceneVector(colliderPos - Vector2.up), blockInfo); placedBlock = true; if (isDebugging) { Debug.Log("Down"); } } //up else if (DiffOfBlockAndPoint.y <= 0.5f) { blockGridController.SetBlock(blockGridController.FindGamePosWithSceneVector(colliderPos + Vector2.up), blockInfo); placedBlock = true; if (isDebugging) { Debug.Log("Up"); } } //check for if the player placed block if (placedBlock) { //delete the block on ur current hand PlayerHotBarSlotController currentSelectedHotBarSlotController = PlayerInventoryController.Instance.GetCurrentSelectedHotBarSlotController(); SlotInfo selectedHotBarSlotInfo = currentSelectedHotBarSlotController.slotInfoContainer; selectedHotBarSlotInfo.Add(-1); currentSelectedHotBarSlotController.UpdateAllDisplay(); //play sound check if there is sounds if (blockInfo.blockBreakSoundInfo.Length != 0) { //play sound int randomIndex = Random.Range(0, blockInfo.blockBreakSoundInfo.Length); SoundManager.Instance.audioSource.volume = blockLoudNess; SoundManager.Instance.ChangeWithSoundInfoAndPlay(blockInfo.blockBreakSoundInfo[randomIndex]); } } } } }