Guest User

Untitled

a guest
Dec 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. # Item Counter
  2.  
  3. This will show you how to create a counter for how many items left in a scene. Before starting, the Item Collection Script needs to be
  4. made first. Refer to the `ItemCollection.md` Gist.
  5.  
  6. ## Creating an event system
  7.  
  8. In your unity scene, at the top of the screen, go to GameObject > UI > Event System.
  9.  
  10. ## Creating the UI Text
  11.  
  12. At the top of the screen, go to GameObject > UI > Text. This creates a canvas and text.
  13.  
  14. Go into 2D view by pressing the 2D button just above the scene window. With the Text selected in the hierarchy, press F2 to rename
  15. the text to `ObjectNum` (YOU MUST CALL IT THIS). Press F to find the text in the screen window.
  16.  
  17. Move the text somewhere in the canvas, and in the text settings, Change the Font size to 50. You will have to readjust the size of
  18. the text box in order to see the text.
  19.  
  20. ## Creating the Script
  21.  
  22. In the Event System's settings on the right side of the screen, press Add Component > New Script. Name this script `CountObjects`.
  23.  
  24. Right click on the Script and press Edit Script to open the script.
  25.  
  26. Under Line 3, type in `Using UnityEngine.UI`. This makes sure that your script refers to UI in Unity.
  27.  
  28. under `public class CountObjects : MonoBehaviour {`, Create a `GameObject` and call it "ObjUI".
  29.  
  30. under `void Start()`, inside the braces(curly brackets), type in `ObjUI = GameObject.Find("ObjectNum")` (This is why it is essential
  31. that you name the text "ObjectNum").
  32.  
  33. Now, under `void Update()` inside the braces, type `objUI.GetComponent<Text>().text = Collect.objects.ToString()`
Add Comment
Please, Sign In to add comment