private void PlayerBreakBlockAtPointingDir() { RaycastHit2D raycastHit2D = GetRayCastHitAtPlayerLooking(); //then break the block that is ray casting if (raycastHit2D != new RaycastHit2D()) { //variables BlockInfo gottedBlockInfo = raycastHit2D.collider.GetComponent <BlockInfoContainer>().blockInfo; //destroy this block Destroy(raycastHit2D.collider.gameObject); //Thread.Sleep(0); //get the block to player direction Vector2 blockToPlayerDir = transform.position - raycastHit2D.transform.position; //spawn a blockDestroyEffect on the position that is on the block for good effects GameObject Instance = SpawnBlockDestroyEffectAtPos(raycastHit2D.transform.position); //then instantiate the block out (this block's block info) GameObject spawnedItem = Instantiate(ItemOBJGamePrefab, raycastHit2D.transform.position, Quaternion.identity, ItemParentTo) as GameObject; //get the current spawned item's slot info container ItemSlotSlotItemContainer spawnedItemSlotContainer = spawnedItem.GetComponent <ItemSlotSlotItemContainer>(); //and it's spawned item slot sprite renderer to change the sprite for the item to good lookin' SpriteRenderer spawnedItemSlotSpriteRenderer = spawnedItem.gameObject.GetComponentInChildren <SpriteRenderer>(); //set the things for the item OBJ spawnedItemSlotContainer.blockInfo = gottedBlockInfo; spawnedItemSlotSpriteRenderer.sprite = gottedBlockInfo.sprite; //this thing is changing the instantiated spawned destroy effect's sprite and change the texture into random texture, but I dunno how so .... // ParticleSystem instanceParticleSystem = Instance.GetComponent<ParticleSystem>(); // Texture2D gottedBlockInfoTexture = gottedBlockInfo.sprite.texture; // instanceParticleSystem.startColor = gottedBlockInfoTexture.GetPixel(Random.Range(0,gottedBlockInfoTexture.width),Random.Range(0,gottedBlockInfoTexture.height)); if (gottedBlockInfo != null) { if (gottedBlockInfo.blockBreakSoundInfo.Length != 0) { int randomIndex = Random.Range(0, gottedBlockInfo.blockBreakSoundInfo.Length); SoundManager.Instance.audioSource.volume = blockLoudNess; SoundManager.Instance.ChangeWithSoundInfoAndPlay(gottedBlockInfo.blockBreakSoundInfo[randomIndex]); } } if (isDebugging) { Debug.Log("destroyed a block at: " + raycastHit2D.transform.position); } } }
private void OnCollisionEnter2D(Collision2D other) { if (other.collider.CompareTag("ItemEntity")) { ItemSlotSlotItemContainer thisItemSlotSlotItemContainer = other.gameObject.GetComponent <ItemSlotSlotItemContainer>(); if (thisItemSlotSlotItemContainer.blockInfo != null) { PerformPlayerRecievedAnItem(thisItemSlotSlotItemContainer.blockInfo); } else if (thisItemSlotSlotItemContainer.itemInfo != null) { PerformPlayerRecievedAnItem(thisItemSlotSlotItemContainer.itemInfo); } else { Debug.Log("This item Entity is has no Item's in it! Item Instance ID:" + other.gameObject.GetInstanceID()); } Destroy(other.gameObject); } }
private void Start() { playerTrans = PlayerStatContainer.Instance.GetComponent <Transform>(); rigidBody2D = GetComponent <Rigidbody2D>(); thisSlotItemContainer = GetComponent <ItemSlotSlotItemContainer>(); }