Beispiel #1
0
    private void Update()
    {
        if (buildManager.GetBuildMode() != BuildManager.Mode.PUT_ON_GRID_MODE)
        {
            if (cursor != null)
            {
                SetCursor(null);
            }

            return;
        }

        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            Vector3 point = grid.SnapToGrid(hit.point);

            int     width      = buildManager.GetBlueprint().width;
            int     height     = buildManager.GetBlueprint().height;
            float   x          = point.x + (width - 1) / 2.0f;
            float   z          = point.z - (height - 1) / 2.0f;
            Vector3 finalPoint = new Vector3(x - 6.1f, 0f + 5, z - 6.1f);
            cursor.transform.position = finalPoint;

            if (grid.CanPutOnGrid((int)point.x, (int)point.z, width, height))
            {
                if (typeHightlight == 1)
                {
                    return;
                }

                cursorMaterial.SetColor("_OutlineColor", blueColor);
                typeHightlight = 1;
            }
            else
            {
                if (hit.collider.CompareTag("Background"))
                {
                    if (typeHightlight == 0)
                    {
                        return;
                    }

                    cursorMaterial.SetColor("_OutlineColor", yellowCollor);
                    typeHightlight = 0;
                }
                else
                {
                    if (typeHightlight == 2)
                    {
                        return;
                    }

                    cursorMaterial.SetColor("_OutlineColor", redCollor);
                    typeHightlight = 2;
                }
            }
        }
    }