|
Hey guys, So I am trying to get my brother familiar with programming, since that is what he says he wants to do as a career. Therefore, I have set-up this simple recreation of PacMan to demonstrate moving a character, dynamically interacting with objects, and eventually adding enemy AI. Then I ran across a problem I have encountered twice before, but I forgot how I fixed - my Score and Pellets Collected GUI.Labels were updating, but leaving previous font behind. I've attached a screenshot showing what I mean - notice how Score and Pellets Collected have other numbers remaining behind them, while Pellets Remaining does not. I currently have my GUI in my GameManager class, but it will likely be moved by the end of the project, if necessary. I use GameManager as a warehouse for scores, stats, and other variables of the sort. The problem is on the Score and Pellets Collected GUI.Labels, and not the Pellets Left GUI.Label. I have a feeling this is because pelletsLeft is being updated in the Update method, while Score and Pellets Collected are only being updated in the OnGUI method. If I am correct, how would I work around this? I am a new game developer myself, but I wanted to show my brother what was possible with less than a year of experience. I don't know all the tricks yet, so any tips are welcome. And yes, I have checked to see if this has been asked before, which I found nothing of use. I have spent the last 2 hours pondering over this. Hopefully some one in the community has the answer. Thanks in advance.
(comments are locked)
|
|
Check the clear flags on your camera. If not set, they'll continually render over themselves. (no clear screen calls) Checked the clear flags on my camera, it was set to Skybox. I don't typically alter that setting, so I had a feeling it wasn't the problem. Is there a certain script to attach to my camera gameobject that would help?
Jul 31 '12 at 03:53 PM
Z13J
Only other thing I can think of is that you have this same OnGUI on another script. The issue here is that it's drawing over itself. Either because it's not clearing the screen after each draw, or you're drawing twice. Check other scripts in the scene and make sure you don't have repeat OnGUI code possibly?
Jul 31 '12 at 04:43 PM
JChilton
Unfortunately that is not the problem either - I have only used OnGUI in this one class. EDIT: I solved the problem, I had the script attached to a different GameObject as well, meaning it would render GameObjectA's score, which was correct, and GameObjectB's score, which was incorrect, and the same time. JChilton was correct, I just misinterpreted what he was saying. Thanks J!
Aug 01 '12 at 03:54 AM
Z13J
(comments are locked)
|


Try not using the
.ToString()method. Integer variables are automatically converted to strings if attached to a string. Finding your pellets with aFindGameObjectsWithTag()call inUpdate()is asking for trouble.Your brother shouldn't be too concerned; I've only been working with Unity for about 2 months, and I'm well ahead of the design team (which consists of 3 people) while working solo. I hadn't even written anything in C# before this.
Your variable pelletLeft, is it changing all the time? Find functions should be avoided in the Update, you would better place it in the Start function and then place it in an array from which you can get the length. Then in the game you only refer to that array.