Week 11


Refined the item spawner while also implementing the RNG Loot Pool to it

First thing I did was create a ‘chest’, I just used a 3D cube and resized it to look like a footlocker style chest. I then added six 3D cubes (children to the chest) on top of the chest at the location I want items to spawn at, I then coloured each cube to match a rarity colour, from least to most rare the colours are: Grey, White, Green, Blue, Purple, Red. I then set each of the cubes to inactive in the inspector. To give the player the ability to interact with the chest I had to add Box Collider and set Is Trigger to true, I then resized it so that there is enough room for the player to be able to stand within it. I then had to add a RigidBody to the chest for collisions to work, that way it can be interacted with by the player. From here I was able to add the RNGLootTable script I had already created but it had to be edited to work with interactions from the player. To do that I created a Private Void OnTriggerStay (Collider other), doing this allows me to make things interactable within the Box Collider attached to the chest, I then set if (other.tag == “Player”) so that only things with the Player tag (like the player) can interact with the chest, from there I used if (Input.GetKeyDown(KeyCode.E)) (this command allows script to be read when a certain key is press in this case E is pressed down but only while the player character is within the Box Collider) Then inside that command I placed the previously created RNG Loot Spawner system, adding a SetActive(true) command for when the RNG number is selected on the Table (this sets the child cube to active in-game). Then back in Unity in the Inspector for the chest I added the coloured chests from before into the Elements on the RNG Loot Table script, I then also added designated chances for each cube to spawn, Grey being most likely to spawn and Red being least. 

Tutorial used: https://www.youtube.com/watch?v=jobHb38ooXg

Leave a comment

Log in with itch.io to leave a comment.