• We just launched and are currently in beta. Join us as we build and grow the community.

Creating Spawn Point and Scoring

HassaMassa

Modder
Divine
H Rep
0
0
0
Rep
0
H Vouches
0
0
0
Vouches
0
Posts
141
Likes
140
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Operating System

Android

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. [

    HideInInspector]
  4. public

    int

    totalPin;

  5. [

    HideInInspector]
  6. public

    int

    limitPin;

  7. private

    Text countText;

  8. void

    Awake(

    )

    {
  9. totalPin =

    maxPin;
  10. }

  11. // Use this for initialization
  12. void

    Start (

    )

    {
  13. InitializeSpawnVariables (

    )

    ;
  14. }

  15. // Update is called once per frame
  16. void

    Update (

    )

    {

  17. }

  18. void

    InitializeSpawnVariables(

    )

    {
  19. limitPin =

    4

    ;

  20. Vector3[

    ]

    pinPosition =

    new

    [

    ]

    {
  21. new

    Vector3(

    0

    , -

    2.

    0f, 0

    )

    ,
  22. new

    Vector3(

    0

    , -

    2.

    8f, 0

    )

    ,
  23. new

    Vector3(

    0

    , -

    3.

    6f, 0

    )

    ,
  24. new

    Vector3(

    0

    , -

    4.

    4f, 0

    )
  25. }

    ;

  26. for

    (

    int

    i =

    0

    ;

    i <

    limitPin;

    i++

    )

    {
  27. if

    (

    maxPin !=

    0

    )

    {
  28. GameObject newPin =

    Instantiate (

    pin, pinPosition [

    i]

    , Quaternion.

    identity

    )

    as

    GameObject;
  29. if

    (

    i ==

    0

    )
  30. newPin.

    transform

    .

    GetComponent

    <

    Pin>

    (

    )

    .

    isPrepareToShoot

    =

    true

    ;

  31. countText =

    newPin.

    transform

    .

    GetChild

    (

    1

    )

    .

    gameObject

    .

    transform

    .

    GetChild

    (

    0

    )

    .

    gameObject

    .

    GetComponent

    <

    Text>

    (

    )

    ;
  32. countText.

    text

    =

    maxPin.

    ToString

    (

    )

    ;
  33. maxPin--;
  34. }
  35. }



  36. }

  37. public

    void

    IsPrepareToFire(

    )

    {
  38. int

    index =

    0

    ;
  39. Vector3[

    ]

    pinPosition =

    new

    [

    ]

    {
  40. new

    Vector3 (

    0

    , -

    2.

    0f, 0

    )

    ,
  41. new

    Vector3 (

    0

    , -

    2.

    8f, 0

    )

    ,
  42. new

    Vector3 (

    0

    , -

    3.

    6f, 0

    )
  43. }

    ;
  44. GameObject[

    ]

    nextPin =

    GameObject.

    FindGameObjectsWithTag

    (

    "Pin"

    )

    ;
  45. foreach

    (

    GameObject newPin in

    nextPin)

    {
  46. if

    (

    !

    newPin.

    transform

    .

    GetComponent

    <

    Pin>

    (

    )

    .

    hasMove

    )

    {
  47. newPin.

    transform

    .

    position

    =

    Vector3.

    Lerp

    (

    newPin.

    transform

    .

    position

    , pinPosition [

    index]

    , Time.

    time

    )

    ;
  48. if

    (

    index ==

    0

    )

    {
  49. newPin.

    transform

    .

    GetComponent

    <

    Pin>

    (

    )

    .

    isPrepareToShoot

    =

    true

    ;
  50. }
  51. index++;

  52. }

  53. }

  54. if

    (

    maxPin !=

    0

    )

    {
  55. GameObject newPin =

    Instantiate (

    pin, new

    Vector3(

    0

    , -

    4.

    4f, 0

    )

    , Quaternion.

    identity

    )

    as

    GameObject;
  56. countText =

    newPin.

    transform

    .

    GetChild

    (

    1

    )

    .

    gameObject

    .

    transform

    .

    GetChild

    (

    0

    )

    .

    gameObject

    .

    GetComponent

    <

    Text>

    (

    )

    ;
  57. countText.

    text

    =

    maxPin.

    ToString

    (

    )

    ;

  58. maxPin--;
  59. }


  60. }

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

35_1.png

Score Text

36_1.png


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.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

438,622

315,778

315,787

Top