Esempio n. 1
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;

                if (Physics.Raycast(ray, out hitInfo))
                {
                    HexaTile hithexa = hitInfo.collider.GetComponent <HexaTile>();

                    if (hithexa != null)
                    {
                        findhexa        = hithexa.hexa;
                        hithexa.element = 1;
                        hithexa.GetComponent <MeshRenderer>().material = greenmaterial;
                    }
                }
            }
            if (Input.GetMouseButtonDown(1))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;

                if (Physics.Raycast(ray, out hitInfo))
                {
                    HexaTile hithexa = hitInfo.collider.GetComponent <HexaTile>();

                    if (hithexa != null)
                    {
                        hithexa.element = -1;
                        hithexa.GetComponent <MeshRenderer>().material = redmaterial;
                    }
                }
            }
            if (Input.GetMouseButtonDown(2))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;

                if (Physics.Raycast(ray, out hitInfo))
                {
                    HexaTile hithexa = hitInfo.collider.GetComponent <HexaTile>();

                    if (hithexa != null)
                    {
                        hithexa.element = 0;
                        hithexa.GetComponent <MeshRenderer>().material = startmaterial;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 타일을 생성한다.
        /// </summary>
        /// <param name="x">좌표x</param>
        /// <param name="z">좌표z</param>
        /// <param name="i">인덱스</param>
        void CreateTile(int x, int z, int i)
        {
            Vector3 position;

            position.x = (x + z * 0.5f - z / 2) * (HexMetrics.innerRadius * 2f);
            position.y = 0f;
            position.z = z * (HexMetrics.outerRadius * 1.5f);

            HexaTile tile = tiles[i] = Instantiate <HexaTile>(tilePrefab);

            tile.transform.SetParent(transform, false);
            tile.transform.localPosition = position;

            tile.index = i;
            tile.hexa  = Hexa.FromOffsetHexa(x, z);

            tile.gameObject.SetActive(true);

            //Debug.Log(tile.hexa.ToString());
        }