示例#1
0
    private IEnumerator AnimationRoutine(string boolName, int swingPosX, int swingPosY)
    {
        animator.SetBool(boolName, true);

        if (itemClass == Class.Hoe)
        {
            World.instance.WorldChangeClick(swingPosX, swingPosY, World.WorldClickType.Till);
        }
        else if (itemClass == Class.Pickaxe)
        {
            World.instance.WorldChangeClick(swingPosX, swingPosY, World.WorldClickType.Mine);
        }
        else if (itemClass == Class.Axe)
        {
            if (PlayerMovement.instance.InPlayerReach(new Vector2(swingPosX, swingPosY)))
            {
                RaycastHit2D hit = Physics2D.Raycast(new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y), Vector2.zero, 0);
                Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (hit)
                {
                    if (hit.transform.gameObject.CompareTag("Tree"))
                    {
                        TreeBreak hitTree = hit.transform.gameObject.GetComponent <TreeBreak>();
                        //hitTree.SpawnWood(swingPosX, swingPosY);
                    }
                }
            }
        }
        yield return(new WaitForSeconds(0.16f));

        gameObject.SetActive(false);
    }
示例#2
0
 void CheckForClick()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         //Check if a UI button was clicked on
         Vector2      clickPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         RaycastHit2D hit           = Physics2D.Raycast(new Vector2(clickPosition.x, clickPosition.y), Vector2.zero, 0);
         Ray          ray           = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (InventoryManager.instance.PlantableSelected() && World.instance.GetTileAt(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y)).type == Tile.Type.Till)
         {
             InventoryManager.instance.ReduceSelectedItem();
             SeedGrowth seed = Instantiate(basicSeed, new Vector2(Mathf.FloorToInt(clickPosition.x) + 0.5f, Mathf.FloorToInt(clickPosition.y) + 0.5f), Quaternion.identity);
             seed.setPlanted();
         }
         if (!hit && PlayerMovement.instance.InPlayerReach(clickPosition))
         {
             if (Equipment.instance.handheld != null)
             {
                 WorldChangeClick(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y), Equipment.instance.handheld.getClickType());
             }
             WorldChangeClick(Mathf.FloorToInt(clickPosition.x), Mathf.FloorToInt(clickPosition.y), WorldClickType.Break);
         }
         else if (Equipment.instance.handheld != null && Equipment.instance.handheld.getClickType() == WorldClickType.Chop && hit && PlayerMovement.instance.InPlayerReach(clickPosition) && hit.transform.gameObject.CompareTag("Tree"))
         {
             TreeBreak hitTree = hit.transform.gameObject.GetComponent <TreeBreak>();
             hitTree.SpawnWood();
         }
     }
 }