Creating Spawn Point and Scoring
Submitted by razormist on Friday, December 1, 2017 - 17:45.
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:- using UnityEngine.UI;
- public GameObject pin;
- public int maxPin;
- [HideInInspector]
- public int totalPin;
- [HideInInspector]
- public int limitPin;
- private Text countText;
- void Awake(){
- totalPin = maxPin;
- }
- // Use this for initialization
- void Start () {
- InitializeSpawnVariables ();
- }
- // Update is called once per frame
- void Update () {
- }
- void InitializeSpawnVariables(){
- limitPin = 4;
- };
- for (int i = 0; i < limitPin; i++) {
- if(maxPin != 0){
- GameObject newPin = Instantiate (pin, pinPosition [i], Quaternion.identity) as GameObject;
- if (i == 0)
- newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
- countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text> ();
- countText.text = maxPin.ToString ();
- maxPin--;
- }
- }
- }
- public void IsPrepareToFire(){
- int index = 0;
- };
- GameObject[] nextPin = GameObject.FindGameObjectsWithTag("Pin");
- foreach(GameObject newPin in nextPin){
- if(!newPin.transform.GetComponent<Pin>().hasMove){
- newPin.transform.position = Vector3.Lerp (newPin.transform.position, pinPosition [index], Time.time);
- if(index == 0){
- newPin.transform.GetComponent<Pin> ().isPrepareToShoot = true;
- }
- index++;
- }
- }
- if(maxPin != 0){
- countText = newPin.transform.GetChild (1).gameObject.transform.GetChild (0).gameObject.GetComponent<Text>();
- countText.text = maxPin.ToString ();
- maxPin--;
- }
- }
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
Score Text
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.
Add new comment
- 58 views