using System.Collections; using System.Collections.Generic; using UnityEngine; public class MainGame : MonoBehaviour { public int N = 5; public int place = 1; public Color player = Color.red; public Color player2 = Color.green; public GameObject sphere; void Start() { for(int i=1; i<=N; i++) { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.position = new Vector3(i, 0, 0); cube.transform.localScale = Vector3.one*0.7f; } sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.transform.position = new Vector3(place, 1, 0); sphere.GetComponent().material.color = player; DisplayStage("2X"); } public void DisplayStage(string stage) { char playerStr = stage[^1]; sphere.GetComponent().material.color = (playerStr=='X') ? player : player2; place = int.Parse(stage.Substring(0, stage.Length - 1)); } public string GetCurrentStage() { return place.ToString() + ((sphere.GetComponent().material.color == player) ? "X" : "N"); } void Update() { int oldPlace= place; if (sphere.GetComponent().material.color == player2) { if (Input.GetKeyDown(KeyCode.Alpha1)) { place += 1; } if (Input.GetKeyDown(KeyCode.Alpha2)) { place += 2; } if (place > N) { place = oldPlace; } if (place > oldPlace) { sphere.GetComponent().material.color = player; } } sphere.transform.position = new Vector3(place, 1, 0); } }