Author Topic: A few questions  (Read 16294 times)

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
A few questions
« on: July 22, 2014, 01:24:23 PM »
Hello everyone,
A little about my company and myself before I begin:

The name of our company is FireCreation. We are a small group of 18 people. We are obviously using Unity to build our first game for retail use.

I am 32 years old. I am the lead code designer as well as our company's CEO. I have years of experience with C++, LUA, HTML1, and HEX. I started modifying an old game called Marathon, Marathon 2, and Marathon Infinity(in HEX). Followed by Unreal(the first Unreal) and Unreal Tournament(A forum of C++). Then I moved on to Arma, Arma 2, Arma 2 Operation Arrowhead, DayZ the mod, and the mod Domination 2(Arma is C++ oriented). I then turned my sights onto modding Rust(LUA via Oxide). Now I am working with C# in Unity. Even though I might know a great deal of C# I still do not know everything.

I have a few questions, some might have already been asked. Some I might find by the time someone answers them. I want to say sorry in advance for any duplicate questions that someone has already asked. I also want to say sorry for questions that might be obvious to a seasoned coder in C#. I am still learning some of it's advance capabilities. I am also watching all the tutorial videos that these fine people here have made for us. Sadly not only do I have to take care of my company, but I have a wife and an 11th month old that demands quite a bit of my time. So I watch those amazing videos when when I have time.

Now for my questions:

I am using a State Machine for our game. I also created a preliminary UI system before I bought NGUI (I am attaching it to this thread, anyone can use it if they need although with NGUI it has become moot). What I am trying to do is get a UI to come up when the user looks at the item in question. I had it working with my little UI script. I have RayCast always on(another script) and I also got it to read when nothing is being 'hit'. So what I am asking is how would I get NGUI to have text come up on the user's screen when RayCast hits a specific item?

I am also using a State Machine to have persistent terrain, items, etc. So how would I add the main menu to what I already have? As of right now I have every item(gameobjects, scripts, the State Machine itself, etc) attach itself to an empty gameobject. I tried to attach the 'Control - Background' to this gameobject but I get an error. The UI Root does not child itself to the gameobject but the 'Control - Background' does. I know I am going to need the UI Root for the entire game. How would I go about Getting the UI Root to be persistent through the loading of each scene with my State Machine(child it to the empty gameobject like the Control - Background)? I have thought of making the UI Root replace the empty gameobject and attach everything to the UI Root. Yet before I rip that apart I was hoping to get a few ideas, if any.

There will be more questions to come as I watch more of the tutorials. I will use this same thread to ask them when they arise. I want to thank everyone in advance for even taking the time to read this. I also want to thank the Developers of NGUI. You guys are awesome! Your application will cut my development time in half. The one thing I have noticed with new indie game developers now a days, is they might be pushing out games with amazing gameplay but they forget to have something as basic as a comprehensive UI. To me the UI is just as important as gameplay. It is the first thing you see when the user loads into the game.

So again thank you for your hard work, you have gained an avid supporter!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #1 on: July 22, 2014, 09:31:09 PM »
NGUI performs its own raycasts underneath mouse and touch events, provided the camera that sees the object you're interacting with has a UICamera script attached. NGUI won't perform raycasts into the screen that's not under the mouse or touch event. You can create a custom input method for NGUI that would do that, however (set UICamera.onCustomInput).

How to get the text come up on the screen? Enable the game object that has the UI element you want. Not sure I understand the question. Do you want it to be in the world space, part of your 3D world? If so, create a game object, attach UIPanel to it, and add widgets underneath it. You'll want to scale the panel object so that it's small first though (0.01, 0.01, 0.01 for example). You don't need the UIRoot for in-game UIs.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #2 on: July 23, 2014, 03:36:31 PM »
NGUI performs its own raycasts underneath mouse and touch events, provided the camera that sees the object you're interacting with has a UICamera script attached. NGUI won't perform raycasts into the screen that's not under the mouse or touch event. You can create a custom input method for NGUI that would do that, however (set UICamera.onCustomInput).
Thank you. Is this how I get game data information to show on the UI for the HUD? I will search for it as well. I have not had time to dive into NGUI as I have been watching the tutorials. Just thought I would ask here in case I can not find it.

How to get the text come up on the screen? Enable the game object that has the UI element you want. Not sure I understand the question. Do you want it to be in the world space, part of your 3D world? If so, create a game object, attach UIPanel to it, and add widgets underneath it. You'll want to scale the panel object so that it's small first though (0.01, 0.01, 0.01 for example). You don't need the UIRoot for in-game UIs.
I was meaning a HUD. So if you look at a specific rock it says "Use bla to do bla" on the players view.

I should also mention that my game is a first person shooter. Thank you again for your time.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #3 on: July 23, 2014, 09:08:09 PM »
Nothing to it. When you add your first widget to the scene, NGUI will make a new camera for you that will be used to draw the UI. This camera will have a UICamera script attached, meaning it will be capable of sending out events to widgets. If you attach UICamera to your main camera, your main camera will also be sending out NGUI events and your in-game colliders will be receiving events as well. Leave the 2D (HUD) camera stationary. When you want to display something over something else, use transform.OverlayPosition.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #4 on: July 26, 2014, 01:05:05 AM »
Awesome that's exactly what I want. Thank you so much! Also I was able to start my State Machine from a button by setting it up like you(or one of your employees?) did on the walkthroughs here. I made an invisible sprite and gave it a script to start it. I am sure I will have more questions soon. I hope you do not mind me adding them to this thread.

You guys are amazing. Thank you again!

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #5 on: July 26, 2014, 01:12:01 PM »
Ok another question:
I have made my buttons as I have said before. That was super easy and I thank you and your crew for this. I am however having an issue with the button placement. I have used your anchor system to get it to resize to the screen so no matter what resolution the game is set at the button will resize accordingly. My problem is that the button stretches to an inch of the side of the screen. I have made some progress with adding an invisible sprite and anchoring it to this. Sadly it doesn't make for a good look on lower resolutions. Is there a setting to set the offset of the anchor? I will post some pictures here if you don't mind taking a look as I think that my words don't do the issue justice.

What I am trying to do:
Make a button that resizes when the screen resolution changes.
Sizes we support:
1920 x 1080
      |
      |
     \ /
640 x 480
Everything in between those. I just need the button not to be almost the size of the screen when using 640 x 480. Thank you in advance.

I will have to post twice to get all the pictures as it's 1.3MB  ::)

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #6 on: July 26, 2014, 01:12:47 PM »
Ok here is the other file. Sorry I had to double post.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #7 on: July 27, 2014, 03:15:19 AM »
Use the layout system to your advantage ("Anchors" section under any widget). Consult UIRect documentation page and watch the video tutorials that cover the layout system. You can make any widget scale itself based on some other rectangle, such as that of the screen size.

Also note that the absolute easiest way to handle screen resolution changes is to change your UIRoot to "Fixed Size" type. Consult UIRoot's documentation page for an explanation.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #8 on: August 05, 2014, 04:38:40 PM »
Well you have been such a big help! However I have to ask another stupid question. I think you have explained it but I am confused as my situation is a bit different. After the Title screen and the options menu I have a FPS cam prefab that is called into game via code so that it's not there until you are out of the menu. What I need is to build a HUD on the FPS cam that is called into the game. How would I do that? I figure I would have to add it to the prefab itself. Sadly I don't know how to go about doing this. If you can direct me to a tutorial or if it's as easy as making a main menu.

Thank you in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #9 on: August 06, 2014, 08:41:51 PM »
I wouldn't add a separate UI just for that. I would just create your HUD UI elements alongside your existing ones, just underneath its own UIPanel. This way you can order it to the front or back easily. When you enable the FPS camera, just turn on the HUD panel as well. Keep its game object disabled otherwise.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #10 on: September 05, 2014, 05:02:09 PM »
Ok so things have been long going. I stopped the UI system to work on other areas I needed to fix. I am back on the UI system again. I have built a UI system with NGUI for both my inventory and HUD. The problem I am getting is calling the UI for the inventory with the 'I' key and have it overlay the main camera. I know the answer is staring me in the face. I have made the UI panel for my inventory. I just don't know how to have to come up on my Main Camera.

I can make unity switch from the UI panel's camera I have made for the inventory then back to the main camera with no problem. What I was hoping is to get an overly of the inventory window over my FPS view. So when I hit 'I' it shows on the screen and you can still see the FPS view in the background. I guess what is stumping me is getting NGUI attached to my FPSCamera prefab. So for the sake of argument, lets say I am using the Controller that comes with unity.(The prefab has the name of "First Person Controller" under the "Standard Assets/Character Controllers/" if you import the "Character Controllers" Asset.)

So with that Prefab how would I go about adding a HUD and an Inventory system. Like I said I already have it so the user can switch between a UI Panel and the main camera. That however does not put the Inventory UI over the main camera, it's taking the user to a 'new' camera. That's not what I want. I want the inventory UI to overlay the main camera. I also want to do something similar to the HUD, it will only come up when the player is hit(I already have the code for that) and fade after a few seconds.

I am just confused on how to attach it to the main camera I have already made. That way no matter what way you are looking with the mouse(In First Person View) the inventory will still come up on that camera. I have even watched most all the walkthrough vids. So if it was there in your walkthroughs, please post where and I will go over it again. Or if there is another thread on this I would be more than happy to read it over. I would ask if you could possibly give me some step by step on how you would attach it that would be amazing!

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #11 on: September 06, 2014, 02:01:55 AM »
Which camera the UI is drawn by is determined by the game object's layer, same as any other renderer.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #12 on: September 06, 2014, 01:05:23 PM »
So sticking each camera on the same layer will have one render over another if 'I' is pushed? Like I said I have one cam turn off and another on to get an 'inventory'. The problem is, I want what is on another panel I made in NGUI to overlay the one on my current FPS camera(Not made by NGUI). Or at least add NGUI properties to my current FPS camera. I am really at a loss for words on how this is done. Now I am not saying you are wrong, it's just because I don't know what you mean. How will the game's layers help in this situation?

I hate saying it but I might need a bit of a detailed walkthrough on this, if you would not mind.
Thank you

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: A few questions
« Reply #13 on: September 07, 2014, 08:32:43 AM »
UI camera, when it's created by NGUI, will automatically disable the layer it's drawing. This won't happen if you copy/paste the UI from somewhere.

Only ONE camera needs to be able to see the UI layer. For example if you have a "UI" layer, and your UI is on that layer, then you must make sure that the Main Camera does not draw the UI layer.

If you have two different UIs (for example 3D and 2D), then you must ensure that each one is on a different layer, and the UICamera that draws that UI only sees that layer.

SoullessDreamer

  • Newbie
  • *
  • Thank You
  • -Given: 8
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: A few questions
« Reply #14 on: September 11, 2014, 05:39:34 PM »
Ok this helped me a lot as I have not worked to much with layers through unity. Before I was using all layers though code only. In fact most everything I do is with code vs unity's panels. My old UI system I built though code used one layer and keys toggled on and off the UI(HUD and Inventory). So I thank you for being patient with me. Sorry it took so long to understand what you were trying to convey.

Thank you again, I will be back with more questions if necessary but for now I can move forward.