Creating Spawn Point and Scoring

Operating System

Creating Spawn Point

The Spawn Point manages the spawning of Pin when the Player touches the screen. First create a GameObject rename it as Spawn Point. Create a C# script save it to Gameplay folder as Spawner. Import this module first:
  1. using UnityEngine.UI;
Write these blocks of code inside the Spawner class
  1. public GameObject pin;
  2. public int maxPin;
  3.  
  4. [HideInInspector]
  5. public int totalPin;
  6.  
  7. [HideInInspector]
  8. public int limitPin;
  9.  
  10. private Text countText;
  11.  
  12. void Awake(){
  13. totalPin = maxPin;
  14. }
  15.  
  16. // Use this for initialization
  17. void Start () {
  18. InitializeSpawnVariables ();
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23.  
  24. }
  25.  
  26. void InitializeSpawnVariables(){
  27. limitPin = 4;
  28.  
  29. Vector3[] pinPosition = new[] {
  30. new Vector3(0, -2.0f, 0),
  31. new Vector3(0, -2.8f, 0),
  32. new Vector3(0, -3.6f, 0),
  33. new Vector3(0, -4.4f, 0)
  34. };
  35.  
  36. for (int i = 0; i < limitPin; i++) {
  37. if(maxPin != 0){
  38. GameObject newPin = Instantiate (pin, pinPosition [i], Quaternion.identity) as GameObject;
  39. if (i == 0)
  40. newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
  41.  
  42. countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text> ();
  43. countText.text = maxPin.ToString ();
  44. maxPin--;
  45. }
  46. }
  47.  
  48.  
  49.  
  50. }
  51.  
  52. public void IsPrepareToFire(){
  53. int index = 0;
  54. Vector3[] pinPosition = new[] {
  55. new Vector3 (0, -2.0f, 0),
  56. new Vector3 (0, -2.8f, 0),
  57. new Vector3 (0, -3.6f, 0)
  58. };
  59. GameObject[] nextPin = GameObject.FindGameObjectsWithTag("Pin");
  60. foreach(GameObject newPin in nextPin){
  61. if(!newPin.transform.GetComponent<Pin>().hasMove){
  62. newPin.transform.position = Vector3.Lerp (newPin.transform.position, pinPosition [index], Time.time);
  63. if(index == 0){
  64. newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
  65. }
  66. index++;
  67.  
  68. }
  69.  
  70. }
  71.  
  72. if(maxPin != 0){
  73. GameObject newPin = Instantiate (pin, new Vector3(0, -4.4f, 0), Quaternion.identity) as GameObject;
  74. countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text>();
  75. countText.text = maxPin.ToString ();
  76.  
  77. maxPin--;
  78. }
  79.  
  80.  
  81. }

Creating the Scoring

We will create now the Scoring, this will count all the Pins that are success pinned to the Target. To do this first create an UI Text, and then set each components as shown in the image.

Score UI

tut35

Score Text

tut36

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Tags

Add new comment