예제 #1
0
        public override void Update()
        {
            Vector3 mouse;

            if (RaycastMousePosition(out mouse))
            {
                if (Input.GetKeyDown(KeyCode.R))
                {
                    ghost.Rotate(true);
                    rotations = (rotations + 1) % 4;
                }

                Vector3 snappedPosition = grid.SnapObjectWorldPosition(mouse, ghost);
                ghost.transform.position = snappedPosition;

                if (Input.GetMouseButtonDown(0) && CanPlaceObject(snappedPosition, ghost))
                {
                    if (EventSystem.current.IsPointerOverGameObject() == false)
                    {
                        if (grid.PlaceObject(snappedPosition, ghost))
                        {
                            OnObjectPlaced(ghost);
                            ghost = CreateGhost();
                            ghost.transform.position = snappedPosition;
                        }
                    }
                }
            }
        }
예제 #2
0
        private GridObject CreateGhost()
        {
            GridObject obj = Instantiate(objectPrefab);

            for (int i = 0; i < rotations; i++)
            {
                obj.Rotate(true);
            }

            return(obj);
        }