0

I am working on the 2D Isometric RTS project. It's like They are Billions or Starcraft. But while working on the map-editor, RayCast faced an unbreakable problem with NGUI. Although you must create the ground when you click the mouse, UICamera.hoveredObject will continue to return UIRoot

Scenes returning UIRoot

private void CreateTileOnMousePos()
{
    Debug.Log(UICamera.hoveredObject);
    if (UICamera.hoveredObject == null)
    {
        RaycastHit2D hit;
        if (hit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition)))//, grid.unwalkableMask))
        {
            Node node = grid.NodeFromWorldPoint(hit.point);
            Vector3Int pos = tilemaps[0].WorldToCell(node.worldPosition);// + tilemaps[0].tileAnchor);

            node.enviormentTile = EnviormentTile.Gress;
            tilemaps[0].SetTile(pos, tilePrefabs[0]);
        }
    }
}

If UIRoot's SetActive is off, of course it works. Select another tile or save/load map information through UIButton. I want to use these NGUI to implement the interface of real game I don't know if the transition is stupid because it's my first time working on it.

I would appreciate it if you could tell me how to do what I intended without turning off UIRoot SetActive

===========================================================================

I don't know how to use GraphicRayCast due to lack of skills, but first I solved it by that method.

if (UICamera.Raycast(Input.mousePosition) == true)
    {
        Debug.Log("UICamera.Raycast ture");
    }
    else
    {
        RaycastHit2D hit;

        if (hit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition)))//, grid.unwalkableMask))
        {
            Node node = grid.NodeFromWorldPoint(hit.point);
            Vector3Int pos = tilemaps[0].WorldToCell(node.worldPosition);// + tilemaps[0].tileAnchor);

            node.enviormentTile = EnviormentTile.Gress;
            tilemaps[0].SetTile(pos, tilePrefabs[0]);
        }
    }

0 Answers0