using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class crossword : MonoBehaviour {
[SerializeField]
bool Создание;
[SerializeField]
int Уровень;
string[,] MAP;
GameObject canvas;
GameObject cursor;
int count=860;
GameObject obj;
// Use this for initialization
void Start () {
// Cursor.visible = false;
canvas = new GameObject("Canvas");
canvas.AddComponent<Canvas>();
canvas.GetComponent<RectTransform>().localScale = new Vector3(0.1f, 0.1f, 0.01f);
canvas.GetComponent<RectTransform>().transform.position = new Vector3(canvas.transform.position.x+10/2-0.5f, canvas.transform.position.y + 10 / 2 - 0.5f, canvas.transform.position.z + 10 / 2 - 0.5f);
cursor = GameObject.CreatePrimitive(PrimitiveType.Plane);
cursor.name = "Cursor";
cursor.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y));
cursor.transform.eulerAngles = new Vector3(-90, 0, 0);
cursor.transform.localScale = new Vector3(0.098f, 0.1f, 0.098f);
cursor.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
cursor.GetComponent<Renderer>().material.color = Color.yellow;
cursor.GetComponent<MeshCollider>().enabled = false;
MAP = new string[21, 11];
for (int i = 21; i > 0; i--)
{
for (int j = 11; j >0; j--)
{
if (PlayerPrefs.GetString("" + i + j+1000*Уровень).Length == 1)
{
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.position = new Vector3(i - 10, j - 5);
plane.transform.eulerAngles = new Vector3(-90, 0, 0);
plane.transform.localScale = new Vector3(0.098f, 0.1f, 0.098f);
plane.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
GameObject text = new GameObject("Text");
text.transform.parent = canvas.transform;
text.AddComponent<Text>();
text.transform.position = new Vector3(i - 10, j - 5, -5);
text.GetComponent<RectTransform>().transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
text.GetComponent<Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
text.GetComponent<Text>().fontSize = 90;
text.GetComponent<Text>().color = Color.black;
text.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
plane.transform.parent = text.transform;
}
if (PlayerPrefs.GetString("" + i + j+1000*Уровень).Length > 1)
{
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.name = "Вопрос";
plane.transform.position = new Vector3(i - 10, j - 5);
plane.transform.eulerAngles = new Vector3(-90, 0, 0);
plane.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
plane.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
plane.GetComponent<Renderer>().material.color = Color.gray;
GameObject text = new GameObject("Text");
text.transform.parent = canvas.transform;
text.AddComponent<Text>();
text.transform.position = new Vector3(i - 10, j - 5, -5);
text.GetComponent<RectTransform>().transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
text.GetComponent<Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
text.GetComponent<Text>().fontSize = 10;
text.GetComponent<Text>().color = Color.black;
text.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
plane.transform.parent = text.transform;
text.GetComponent<Text>().text = PlayerPrefs.GetString("" + i + j +1000* Уровень);
if(!Создание) cursor.GetComponent<MeshCollider>().enabled = false;
}
}
}
}
RaycastHit hit,hit1;
bool win = false;
// Update is called once per frame
void Update()
{
if(win == false&& !Создание) {
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 11; j++)
{
if (i == 20 && j == 10)
{
win = true;
int count = 0 ;
for (int k = 0; k < 21; k++)
{
for (int v = 0; v < 11; v++)
{
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.position = new Vector3(k - 10, v - 5);
plane.transform.eulerAngles = new Vector3(-90, 0, 0);
plane.transform.localScale = new Vector3(0.098f, 0.1f, 0.098f);
plane.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
plane.GetComponent<Renderer>().material.color = Color.green;
}
}
}
RaycastHit hit2;
if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), new Vector3(i - 10, j - 5) - Camera.main.ScreenToWorldPoint(Input.mousePosition), out hit2))
{
if (MAP[i,j]!=PlayerPrefs.GetString(""+i+j+1000*Уровень))
{
i = 21;
j = 11;
}
}
}
}
}
cursor.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y), -0.001f);
if (Physics.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), transform.forward, out hit))
{
if (Нажато)
{
if (Буква != "" + KeyCode.Backspace && Буква.Length == 1)
{
if (Буква != "None")
{
if (hit.collider.name == "Вопрос")
{
if (Создание)
{
MAP[Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x) + 10, Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y) + 5] += Буква;
hit.collider.gameObject.GetComponentInParent<Text>().text += Буква;
}
}
else
{
MAP[Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x) + 10, Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y) + 5] = Буква;
hit.collider.gameObject.GetComponentInParent<Text>().text = Буква;
}
}
}
if (Input.GetKeyDown(KeyCode.Backspace))
{
hit.collider.gameObject.GetComponentInParent<Text>().text = hit.collider.gameObject.GetComponentInParent<Text>().text.Remove(hit.collider.gameObject.GetComponentInParent<Text>().text.Length - 1);
}
if (Input.GetKeyDown(KeyCode.Space))
{
MAP[Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x) + 10, Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y) + 5] += " ";
hit.collider.gameObject.GetComponentInParent<Text>().text += " ";
}
}
if(Создание)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
hit.collider.GetComponentInParent<Text>().text="";
MAP[Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x) + 10, Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y) + 5] = null;
Destroy(hit.collider.gameObject);
}
}
}
else
{
if (Создание)
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y));
plane.transform.eulerAngles = new Vector3(-90, 0, 0);
plane.transform.localScale = new Vector3(0.098f, 0.1f, 0.098f);
plane.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
GameObject text = new GameObject("Text");
text.transform.parent = canvas.transform;
text.AddComponent<Text>();
text.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y), -5);
text.GetComponent<RectTransform>().transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
text.GetComponent<Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
text.GetComponent<Text>().fontSize = 90;
text.GetComponent<Text>().color = Color.black;
text.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
plane.transform.parent = text.transform;
}
if (Input.GetKeyDown(KeyCode.Mouse1))
{
GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
plane.name = "Вопрос";
plane.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y));
plane.transform.eulerAngles = new Vector3(-90, 0, 0);
plane.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
plane.GetComponent<Renderer>().material.shader = Shader.Find("Sprites/Default");
plane.GetComponent<Renderer>().material.color = Color.gray;
GameObject text = new GameObject("Text");
text.transform.parent = canvas.transform;
text.AddComponent<Text>();
text.transform.position = new Vector3(Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).x), Mathf.RoundToInt(Camera.main.ScreenToWorldPoint(Input.mousePosition).y), -5);
text.GetComponent<RectTransform>().transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
text.GetComponent<Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
text.GetComponent<Text>().fontSize = 10;
text.GetComponent<Text>().color = Color.black;
text.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
plane.transform.parent = text.transform;
}
}
}
}
bool Нажато = false;
string Буква;
private void OnGUI()
{
Event e = Event.current;
if (e.isKey) Буква = "" + e.keyCode;
if (e.isKey) Нажато = true;
else Нажато = false;
}
private void OnApplicationQuit()
{
if (Создание)
{
for (int i = 0; i < 21; i++)
{
for (int j = 0; j < 11; j++)
PlayerPrefs.SetString("" + i + j+1000*Уровень, MAP[i, j]);
}
}
}
}