Example #1
0
        void MovePiece(Transform t, float x, float z, float rotation)
        {
            MoveableUnit unit = t.gameObject.GetComponent <MoveableUnit>();

            unit.SpawnGhost();
            unit.NetworkMoveUnit(x, z);
            unit.NetworkRotateUnit(rotation);
        }
Example #2
0
        public override void Update()
        {
            if (selectedObject != null)
            {
                currRot = selectedObject.transform.rotation.eulerAngles;
            }
            else
            {
                currRot = Vector3.zero;
            }
            //TODO function this out, and get rid of magic numbers.
            if (Input.GetMouseButtonDown(0))
            {
                Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (!moved && selectedObject == null && Physics.Raycast(ray, out hit, 100.0f, raycastLayer))
                {
                    switch (hit.transform.gameObject.tag)
                    {
                    case "Movable":
                    {
                        MoveableUnit unit = hit.transform.gameObject.GetComponentInParent <MoveableUnit>();
                        if (unit != null && unit.GetOwner() == playerNumber)
                        {
                            selectedObject             = unit.gameObject;
                            objectPositionWhenSelected = selectedObject.transform.position;
                            //objectRotationWhenSelected = selectedObject.transform.rotation;
                            objectRotationWhenSelected = selectedObject.transform.rotation.eulerAngles;
                            selectedObject.GetComponent <RotateUnit>().ObjectSelected();
                            blah = selectedObject.transform.rotation.eulerAngles.y;

                            Transform go = selectedObject.transform.FindDeepChild("FloorIgnorer");
                            if (go != null)
                            {
                                go.gameObject.SetActive(false);
                            }
                            //selectedObject.transform.Find("FloorIgnorer").gameObject.SetActive(false);
                            unit.UnitSelected();
                        }
                        break;
                    }

                    case "Laser":
                    {
                        Debug.Log("laser hit");
                        if (hit.transform.gameObject.GetComponent <LaserGun>().GetOwner() == playerNumber)
                        {
                            hit.transform.gameObject.GetComponent <LaserGun>().ToggleLaserAim();
                            movedObject = hit.transform.gameObject;
                        }
                        break;
                    }

                    default:
                    {
                        Debug.Log("Correct tag was not hit. Object was: " + hit.transform.gameObject.name + " with a tag of: " + hit.transform.gameObject.tag);
                        break;
                    }
                    }
                }
                else if (selectedObject != null && Physics.Raycast(ray, out hit, 100.0f, raycastLayerWithSelectedObject))
                {
                    switch (hit.transform.gameObject.tag)
                    {
                    case "Tile":
                    {
                        if (IsNewLocation(hit) && IsValidLocation(hit))
                        {
                            Debug.Log("movemade: tile");
                            MoveableUnit u = selectedObject.GetComponent <MoveableUnit>();
                            if (u != null)
                            {
                                u.UnitUnselected();
                            }
                            moved          = true;
                            movedObject    = selectedObject;
                            selectedObject = null;
                            moveMade.Raise();
                        }
                        else
                        {
                            Debug.Log("undomove: tile");
                            UndoMove();
                        }
                        break;
                    }

                    case "Movable":
                    {
                        MoveableUnit unit = hit.transform.GetComponentInParent <MoveableUnit>();
                        if (unit != null && selectedObject == unit.gameObject && IsNewLocation(hit) && IsValidLocation(hit))
                        {
                            Debug.Log("movemade: movable");
                            //MoveableUnit u = selectedObject.GetComponentInParent<MoveableUnit>();
                            if (unit != null)
                            {
                                unit.UnitUnselected();
                            }
                            moved          = true;
                            movedObject    = selectedObject;
                            selectedObject = null;
                            moveMade.Raise();
                        }
                        else
                        {
                            if (unit == null)
                            {
                                Debug.Log("unit is null");
                            }
                            if (selectedObject != unit.gameObject)
                            {
                                Debug.Log("selectedobject different from unit");
                            }
                            if (!IsNewLocation(hit))
                            {
                                Debug.Log("not new location");
                            }
                            if (!IsValidLocation(hit))
                            {
                                Debug.Log("not valid location");
                            }

                            Debug.Log("undomove: movable");
                            UndoMove();
                        }
                        break;
                    }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                UndoMove();
            }

            OnMouseDrag();
            OnMouseScroll();

            LogDebugInfo();
        }