Esempio n. 1
0
 // Start is called before the first frame update
 void Start()
 {
     playerMoveScript = GetComponent <MovementTest>();
 }
Esempio n. 2
0
    //Used to update the attack scene. each block of code within has been commented
    private void Update()
    {
        //Updates the health seen in the ui according to the players actual health
        if (playerHealth != null)
        {
            health.text = playerHealth.GetComponent <TextMesh>().text;
        }
        else
        {
            health.text = "";
        }

        //Gets the users balance from the database at the start of the scene and stores in static variable (userBalance)
        FirebaseDatabase.DefaultInstance.GetReference("users").GetValueAsync().ContinueWith(task => {
            if (task.IsFaulted)
            {
                // Handle the error...
            }
            else if (task.IsCompleted)
            {
                DataSnapshot dataSnapshot = task.Result;
                // Do something with snapshot...
                foreach (DataSnapshot s in dataSnapshot.Children)
                {
                    if (email.Equals(s.Child("email").Value.ToString()))
                    {
                        //Debug.Log("LOOK HERE " + s.Child("balance").Value.ToString());
                        bal = "£" + s.Child("balance").Value.ToString();
                        if (!onlyOnce)
                        {
                            userBalance = int.Parse(s.Child("balance").Value.ToString());
                            onlyOnce    = true;
                        }
                    }
                }
            }
        });

        /* If the balance has been retrieved from the database then
         * it uses the static variable to update the text representing the players balance on the ui */
        if (onlyOnce)
        {
            balanceText.text = "£" + userBalance.ToString();
        }

        //Once the userID and villages turrets have been retreived from database the village is populated and the load panel is hidden
        if (loadDone && loadDone2)
        {
            for (int i = 0; i < positions.Count; i++)
            {
                //////
                ///new stuff
                GameObject g;
                if (turretTypes[i] == 1)
                {
                    g = (GameObject)Instantiate(turr1);
                }
                else if (turretTypes[i] == 2)
                {
                    g = (GameObject)Instantiate(turr2);
                }
                else
                {
                    g = (GameObject)Instantiate(turr3);
                }
                g.transform.position = positions[i];
                g.transform.SetParent(ground);
            }
            loadingPanel.SetActive(false);
            loadDone = false;
        }

        //If village hub is destroyed then show the win panel else if the player is destroyed show the lose panel
        if (villageHub == null)
        {
            WinPanel.SetActive(true);

            //Stop player moving after killing village by disabling script
            MovementTest mTest = player.GetComponent <MovementTest>();
            mTest.Stop();
            if (!balChangedOnWinOrLose)
            {
                userBalance           = userBalance + 500;
                balChangedOnWinOrLose = true;
                //Show Toast
                WinToastMaker.showToast("Congratulations! You have earned £500", 2);
            }
        }
        else if (player == null)
        {
            gameOverPanel.SetActive(true);
            if (!balChangedOnWinOrLose)
            {
                userBalance           = userBalance - 500;
                balChangedOnWinOrLose = true;
                //Show Toast
                //toastMaker.setTextObj(LoseToastText);
                LoseToastMaker.showToast("You have failed to take over this village. Forced to pay out £500", 2);
            }
        }
    }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     movement = new MovementTest(speed);
 }