Untitled

 avatar
tadotheminer1
csharp
2 years ago
2.1 kB
9
Indexable
Never
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Gamemanager : MonoBehaviour
{
    private bool ongame=false;
    private int scoreofplayerminusone=0;
    private int scoreofplayerplusone=0;
    public string reloadkey;
    public string playerminusonekey;
    public string playerplusonekey;
    Text textplayerminusone;
    Text textplayerplusone;
    void Start()
    {
        textplayerplusone.text=textplayerminusone.text="0";
        Reload(true);
    }
    void Update()
    {
        if(!ongame&&Input.anyKeyDown)
        {
            playerminusone.GetComponent<playermovement>().StartGame();
            playerplusone.GetComponent<playermovement>().StartGame();
            ball.GetComponent<ballscript>().StartGame();
        }
        if(Input.GetKeyDown(reloadkey))
        {
            scoreofplayerminusone=scoreofplayerplusone=0;
            textplayerplusone.text=textplayerminusone.text="0";
            Reload();
        }
    }
    public void Roundended(bool playerthatlost)
    {
        if(playerthatlost)
        {
            scoreofplayerminusone++;
        }
        else
        {
            scoreofplayerplusone++;
        }
        textplayerminusone.text=Convert.ToString(scoreofplayerminusone);
        textplayerplusone.text=Convert.ToString(scoreofplayerplusone);
        Reload();
    }
    void Reload(bool firstround=false)
    {
        if(!firstround)
        {
        Destroy(GameObject.FindWithTag("Player-1"));
        Destroy(GameObject.FindWithTag("Player1"));
        Destroy(GameObject.FindWithTag("Ball"));
        }
        GameObject playerminusone=Instaniate(Player,new Vecto3(-14,0,0));
        playerminusone.GetComponent<playermovement>().key=playerminusonekey;
        playerminusone.tag="Player-1";       
        GameObject playerplusone=Instaniate(Player,new Vecto3(14,0,0));
        playerplusone.GetComponent<playermovement>().key=playerplusonekey;
        playerplusone.tag="Player1";
        Gameobject ball=Instaniate(Ball,new Vector3(0,0,0));
        ongame=false;
    }
}