示例#1
0
    void clickEvent()
    {
        Vector3 mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);

        RaycastHit2D hitGrid = Physics2D.Raycast(mousePos2D, Vector2.zero, LayerMask.GetMask("Grid"));

        if (hitGrid.collider != null && hitGrid.collider.gameObject.tag == "Point")
        {
            turretManager.placeTurret(
                GameObject.Find(hitGrid.collider.gameObject.name).transform.position,
                uiSelection);
        }

        if (hitGrid.collider != null && hitGrid.collider.gameObject.tag == "Wall")
        {
            wallManager.placeWall(
                GameObject.Find(hitGrid.collider.gameObject.name).transform.position,
                GameObject.Find(hitGrid.collider.gameObject.name).transform.rotation,
                uiSelection);
        }
    }