Skip to content

Instantly share code, notes, and snippets.

@Avonexile
Last active November 4, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avonexile/f3066326fc36e5de1aa54cbc06f3f7d2 to your computer and use it in GitHub Desktop.
Save Avonexile/f3066326fc36e5de1aa54cbc06f3f7d2 to your computer and use it in GitHub Desktop.
Slot script for the slots of my Tic-Tac-Toe
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class Slot : MonoBehaviour {
//this buttons text child
public Text myText;
//the value of what player it is
static string value; //turn = false = X | turn = true = O
//which players turn it is
static bool turn;
//board manager reference
public BoardManager boardManager;
//sets the text component turns the text to nothing (to be sure) and sets the first turn
void Awake ()
{
boardManager = GameObject.Find("_Managers").GetComponent<BoardManager>();
myText = GetComponentInChildren<Text>();
myText.text = "";
TurnValue();
}
//changes the value so you know who's turn it is
void TurnValue ()
{
if(turn)
{
value = "O";
}
else
{
value = "X";
}
}
//sets the value in text component. if the text component already has a value, then it wont override
//it also checks for the winning condition
public void SetValue ()
{
if(myText.text != "")
{
return;
}
else
{
myText.text = value;
boardManager.WinningCondition(value);
turn = !turn;
TurnValue();
}
}
//resets the text and the turn
public void ResetValue ()
{
myText.text = "";
turn = false;
TurnValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment