4

I am making a mini map Using render texture to render my Over head cam to my screen and Drawing that texture using NGUI 3.9 every things is fine Apart from When i am Trying to click on My minimap and trying to destroy a object or Geting the point on my Game Floor which is on my World Space rendered by Main Camera Raycast is not reaching it some how i don't know what i am doing wrong Edited: I am using Ngui is because whole Gui of my game is in Ngui so its my requierment

I have Edited my code to a new aproch by this i am able to cast a ray on to my floor but the position of my ray is not accurate

here is my code

 public void TestWithTextureCoords()
    {
        Camera main = UICamera.mainCamera;

        Camera mapCam = transform.GetComponent<Camera>();

        Ray firstRay = main.ScreenPointToRay(Input.mousePosition);
        Debug.DrawLine(firstRay.origin, firstRay.direction);
        RaycastHit textHit;

        if (Physics.Raycast(firstRay, out textHit, main.farClipPlane))
         {
            var hitPoint =  textHit.point;

            Ray scondRay =   mapCam.ViewportPointToRay(hitPoint);

            RaycastHit worldHit;
            if (Physics.Raycast(scondRay, out worldHit, mapCam.farClipPlane))
             {
                Debug.DrawLine(scondRay.origin, worldHit.point, Color.red);

               Debug.Log(" world hit point " + worldHit.point);
                Debug.Log(worldHit.transform.name, worldHit.transform);
             }
         }


}

Please look into it As soon as possible let me know a work around or how it is being done May be I am missing a small Think I have no idea about I have Tried different kind of approaches but all in vain help!

Syed Anwar Fahim
  • 306
  • 5
  • 15
  • 1
    I don't know but why are using NGUI? What's wrong with the new Unity UI? – Programmer Apr 22 '16 at 05:51
  • because its my need i have a whole HUD setup in NGUI and i have to connect it to that so it always render itself relation to Screen Size and it is easy to do without much Calculation and less time consuming... coming back on main issue – Syed Anwar Fahim Apr 22 '16 at 06:49
  • 1
    maybe use the camera used for the minimap instead of `Camera.main`? what was wrong with the part you commented out? i mean this line `Camera mapCam = Camera.main; //transform.GetComponent();` – yes Apr 22 '16 at 10:45
  • @SyedAnwarFahim.I understand that my first comment is not about the issue but I asked that to help you if there is a reason you are not using the new UI. You should only use `NGUI` if your old game uses it. If you are just starting a new game, you should use the new UI. Screen Size is not a problem with the new UI. Simply watch this video https://www.youtube.com/watch?v=ezeoYnLBpnE to understand how to make your game work on multiple displays. What you are trying to do can easily be done in the new UI without hassle. `NGUI` and `OnGUI` questions usually go without being answered. Good luck. – Programmer Apr 22 '16 at 11:28
  • I wouldn't raycast and stuff. You should know the world scale and the minimap scale. As soon as you know (mapCam) where the mouse is above the mini map, you just scale up the Vector2 of that position and tadaa, you have your x, z world coordinates –  Apr 28 '16 at 09:53
  • are you talking about local size which is this case in (1,1,1) of both my mini map and the floor or its something else note: as my floor is in pieces regions i should say, so its difficult to know exact size or something or i can do it with mesh bounds or etc – Syed Anwar Fahim Apr 28 '16 at 10:13

0 Answers0