Ejemplo n.º 1
0
    private void ClickedOnScreen()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2      mousePos = new Vector2(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero, playerRange);

            if (hit.collider != null)
            {
                GameObject currentHit = hit.collider.gameObject;
                Vector3    range      = currentHit.transform.position - playerPos;
                float      rangeID    = Mathf.Sqrt((range.x * range.x) + (range.y * range.y));

                if (rangeID <= playerRange)
                {
                    if (Data.GetHitpoints() > 0)
                    {
                        GameObject.FindGameObjectWithTag("Player").GetComponent <Animator>().SetTrigger("PlayerDig");
                        switch (currentHit.tag)
                        {
                        case "Pickups":
                            GoldInformation goldInformation = currentHit.gameObject.GetComponent <GoldInformation>();
                            Data.LoseHitpoints();
                            playerInformation.UpdateScore(goldInformation.IsHit(playerInformation.GetToolLevel(), playerInformation.GetToolStrength(), currentHit));
                            break;

                        case "Amethyst":
                            AmethystInformation amethystInformation = currentHit.gameObject.GetComponent <AmethystInformation>();
                            Data.LoseHitpoints();
                            playerInformation.UpdateScore(amethystInformation.IsHit(playerInformation.GetToolLevel(), playerInformation.GetToolStrength(), currentHit));
                            break;

                        case "Terrain":
                            TerrainInformation terrainInformation = currentHit.gameObject.GetComponent <TerrainInformation>();
                            Data.LoseHitpoints();
                            playerInformation.UpdateScore(0);
                            terrainInformation.IsHit(playerInformation.GetToolLevel(), playerInformation.GetToolStrength(), currentHit);
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        Data.Restart();
                    }
                }
            }
        }
    }