using UnityEngine; using System.Collections; public class Plaatideloomine : MonoBehaviour { int nr = -1; const int kogus = 5; GameObject valitudNupp = null; GameObject valitudPlaat = null; GameObject[] plaadid = new GameObject[kogus]; void Start () { GameObject plaat = (GameObject)GameObject.Find("kuubik"); for (int i = 0; i < kogus; i++) { GameObject uusPlaat = (GameObject)Instantiate(plaat); plaadid[i] = uusPlaat; uusPlaat.transform.position = new Vector3((float)(-2-i/2.0), i, 0); if (i % 2 == 0) { GameObject uusNupp = (GameObject)Instantiate(GameObject.Find("nupp")); uusNupp.transform.position= new Vector3((float)(-2 - i / 2.0), i+0.5f, 0); uusPlaat.GetComponent().material.color = Color.green; } else { uusPlaat.GetComponent().material.color = Color.yellow; } } } RaycastHit hit = new RaycastHit(); void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { Debug.Log(nr); Ray kiir = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(kiir, out hit, 100)) { hit.collider.GetComponent().material.color = Color.blue; if (nr == -1) { valitudNupp = hit.collider.gameObject; nr = 1; } else { valitudPlaat = hit.collider.gameObject; nr = -1; valitudNupp.transform.position = valitudPlaat.transform.position + Vector3.up * 0.5f; } } } } }