- Home /
Runescape style window?
How would I go about making this? I can do all the HUD etc, but how would I make the actual game above the chat and to the left of inventory / map. As it's enclosed? Any idea how to do this even if it's simple, then please help, I'm stuck at this. Thanks in advance!
EDIT: Haha, figured something out that'll do. I put the scripts on a gameobject instead of the camera, thought they had to be on the camera to be shown. If there's a better way for this let me know ;p
I don't understand what you want. Are you looking to have the game's viewport moved into the upper left corner so that there is room for the inventory and chat at the bottom right? You could easily do that with the Camera's Inspector options.
I made a gameobject and put the GUI scripts onto it, then scaled the camera to fit correctly. What my problem is right now, is that when you click out of the camera (chat for example), it still moves with my click to move script.
/
it still acts as if I'm clicking inside the camera
Assu$$anonymous$$g your game window will be a fixed size, can't you just check the mouse coordinates before running the click-to-move code to make sure that they are within the viewport?
I am new to javascript and so far I have only 'fully' got the hand of unity's GUI system, said in another way, I wouldn't be able to code that since I dont know how to, yet. If I knew how to, I am sure I could use that.
Answer by Tomer-Barkan · Nov 23, 2013 at 03:44 PM
You can set variable "Viewport Rect" either from the inspector, or from code. This specify whit section of the screen the given camera will occupy. You can do this to limit the output of the camera as you describe, or even for split-screen multiplayer.
BTW: if you want clicks outside of the camera to be ignored by certain scripts, all you have to do is check the mouse position and whether it is within the viewport of the camera or not.
Rect camViewport = Camera.main.rect;
Vector3 mousePos = Input.mousePosition;
if (mousePos.x >= camViewport.xMin && mousePos.x <= camViewport.xMax && mousePos.y >= camViewport.yMin && mousePos.y <= camViewport.yMax) {
// do something only when mouse is within the main game window
}
Ah, so I put this into a java script, add the scripts with GetComponent, and those added with GetComponent wont do anything outside the camera?
No, not exactly. This is just the frame of the script. Inside the if statement you have to put your own code, the one you want to execute only when the mouse pointer is within the camera viewport.
For example, if you want to print "Hello" in the log, but only when the user clicks the mouse button within the main camera view:
if (mousePos.x >= camViewport.x$$anonymous$$in && mousePos.x <= camViewport.x$$anonymous$$ax && mousePos.y >= camViewport.y$$anonymous$$in && mousePos.y <= camViewport.y$$anonymous$$ax) {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eycode.$$anonymous$$ouse0) {
Debug.Log("Hello");
}
}
So we check that the mouse position is within the window, then we check that the mouse button was pressed, then we print "Hello" to the debug log.