Unity - How To - Make - Platformer - 17 - Code - Collectible

#unity #how #to #make #platformer #code #collectible How to make collectible in the Unity game? Collectibles are vital points of the game progression. This can be both the main game goal and additional useful bonus. We need to create C# script to make our collectibles work. To repeat: 0. Open ’Collect’ script 1. Create method ’private void OnTriggerEnter2D(Collider2D other)’ 2. Clear unused dependencies - append ’System’, ’’ 3. Create public objects ’GameObject show’, ’GameObject hide’, ’Text score’ 4. Assign score text to int ’calc’ variable via ’’ 5. Increase ’calc’ count by 1 - assign its value to score text 6. Check if calc is bigger or equal melons total count - If so activate ’show’ and deactivate ’hide’ gameObjects 7. At the end of the script place ’Destroy(gameObject)’ - it will remove collectible off the scene 8. Check and fix the errors in the Console if any Next lesson preparations: 0. Select ’Melon’ gameObject 1. Drag N Drop ’Collect’ script to the end of the Inspector 2. Notice that ’Collect (Script)’ section appeared in the Inspector 3. Drag N Drop ’Score’ gameObject to the ’Score’ field in the Inspector under ’Collect (Script)’ section 4. Drag N Drop ’YouWon’ gameObject to the ’Show’ field in the Inspector under ’Collect (Script)’ section
Back to Top