Example #1
0
        void CheckMouse()
        {
            if (Input.GetMouseButtonUp(0))
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.collider.tag == "Block")
                    {
                        NSLevel.Block t = hit.collider.GetComponent <BlockColliderData>().block;

                        if (t.selectable)
                        {
                            MoveToBlock(t);
                        }
                    }
                }
            }
        }
Example #2
0
        protected void CheckMouse()
        {
            if (Input.GetMouseButtonUp(0))
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 1000f, NSGame.Resources.Instance.collisionLayerBlock))
                {
                    NSLevel.Block t = hit.collider.GetComponent <BlockColliderData>().block;

                    if (t.busy)
                    {
                        return;
                    }

                    // If sel block with unit
                    if (t.selectable && t.unit != null)
                    {
                        //IF CLICK ON SELF DROP TOOLS
                        if (t.unit == Context)
                        {
                            if (Context.equippedTool != NSUnit.Tool.TOOL_TYPE.NONE)
                            {
                                Unit  u = null;
                                Block b;
                                switch (Context.equippedTool)
                                {
                                case NSUnit.Tool.TOOL_TYPE.AXE:

                                    u = Instantiate(NSLevel.Resources.Instance.toolAxe).GetComponent <Unit>();
                                    break;


                                case NSUnit.Tool.TOOL_TYPE.SHOVEl:

                                    u = Instantiate(NSLevel.Resources.Instance.toolShovel).GetComponent <Unit>();
                                    break;


                                case NSUnit.Tool.TOOL_TYPE.RACK:

                                    u = Instantiate(NSLevel.Resources.Instance.toolRack).GetComponent <Unit>();

                                    break;
                                }

                                bool found = false;
                                var  bbb   = t.GetAdjacentBlocks();
                                foreach (Block bb in bbb)
                                {
                                    if (bb.unit == null && bb.walkable && !bb.busy)
                                    {
                                        // Context.ChangeEquipTool();
                                        Context.equippedTool = NSUnit.Tool.TOOL_TYPE.NONE;
                                        Context.ChangeEquipTool();
                                        found = true;
                                        u.transform.position = bb.transform.position;
                                        bb.SetUnit(u);
                                        break;
                                    }
                                }

                                if (!found)
                                {
                                    Context.equippedTool = NSUnit.Tool.TOOL_TYPE.NONE;
                                    Context.ChangeEquipTool();
                                    NSLevel.Level.Instance.RainUnit(u);
                                    Destroy(u.gameObject); //destory old one
                                }
                            }


                            return;
                        }

                        // Only works on idle
                        if (TryInteract(t))
                        {
                        }
                    }
                    // If sel block alone
                    else if (t.selectable && t.walkable)
                    {
                        if (FindPath(t))
                        {
                            Path path = CreatePath(t);
                            path.interactOnFinished = false;
                            Context.fsm.SwitchState("Move", path.gameObject);
                        }
                    }
                }
                else
                if (Physics.Raycast(ray, out hit, 1000f, NSGame.Resources.Instance.collisionLayerEstablishment))
                {
                    var col = hit.collider.GetComponent <ColliderData>();
                    var est = col.owner.GetComponent <NSEstablishment.Establishment>();
                    TryInteract(est);
                }
            }
        }