| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class LocalGameScript : MonoBehaviour
- {
- public Transform content;
- public GameObject playerInfoPrefab;
- public Button startButton;
- public Button deleteButton;
- public Text numberOfPlayersText;
- public Text neededToWinText;
- public Text roundText;
- public Text dateStartedText;
- public Text lastPlayedText;
- public Text finishedDateText;
- private int answerTimer;
- private string gameMode;
- private string currentPlayer;
- private string currentPlayerName;
- private int gameId;
- private List<KeyValuePair<string, int>> players;
- public string CurrentPlayerName { get => currentPlayerName; set => currentPlayerName = value; }
- public string CurrentPlayer { get => currentPlayer; set => currentPlayer = value; }
- public string NumberOfPlayers { get => numberOfPlayersText.text; set => numberOfPlayersText.text = value; }
- public int AnswerTimer { get => answerTimer; set => answerTimer = value; }
- public string QuestionsNeededToWin { get => neededToWinText.text; set => neededToWinText.text = value; }
- public string GameMode { get => gameMode; set => gameMode = value; }
- public int GameId { get => gameId; set => gameId = value; }
- public string Round { get => roundText.text; set => roundText.text = value; }
- public string StartDate { get => dateStartedText.text; set => dateStartedText.text = value; }
- public string LastPlayedDate { get => lastPlayedText.text; set => lastPlayedText.text = value; }
- public string FinishedDate { get => finishedDateText.text; set => finishedDateText.text = value; }
- public List<KeyValuePair<string, int>> Players { get => players; set => players = value; }
- private void Start() {
- startButton.onClick.AddListener(StartThisGame);
- deleteButton.onClick.AddListener(DeleteThisGame);
- }
- public void AddPlayer(string name, int points) {
- if (players == null) {
- players = new List<KeyValuePair<string, int>>();
- }
- KeyValuePair<string, int> p = new KeyValuePair<string, int>(name, points);
- Players.Add(p);
- GameObject go = Instantiate(playerInfoPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
- PlayerInfo playerInfo = go.GetComponent<PlayerInfo>();
- playerInfo.SetName(name);
- playerInfo.SetPoints(points);
- playerInfo.transform.SetParent(content);
- playerInfo.transform.SetSiblingIndex(0);
- }
- public void StartThisGame() {
- Debug.Log("CLicked button to start game");
- PlayerPrefs.SetInt("GameId", GameId);
- SceneManager.LoadSceneAsync("narKampen");
- }
- public void DeleteThisGame() {
- Debug.Log("CLicked button to delete game");
- }
- }
|