Jump to content

How to add a screen message in the upper left corner?


Recommended Posts

Hi all,

I'm trying to figure out how to add a screen message in the upper left corner like this:

hQX3Eib.jpg

I know about ScreenMessages.PostScreenMessage, but none of the ScreenMessageStyle options seems to print the message in the upper left in the font shown in the screenshot. Any ideas?

Thanks for the help. :)

Link to comment
Share on other sites

Thanks for the help. :) I figured out that there is a ScreenMessage class, and you use it to set a GUIStyle. It appears that there are a few GUIStyle objects in the ScreenMessages object (I had to get it via FindObjectOfType), and the first one in the array of textStyles has what I need.

Link to comment
Share on other sites

Is there a consensus that ScreenMessage should not be used? Instead you use the ScreenMessages static functions?

ScreenMessages.PostScreenMessage has an override that takes a ScreenMessage object. That's what I'm using, now that I know how.

Link to comment
Share on other sites

  • 2 weeks later...

But be careful, guys, with those messages. You can specify a time-to-live for the message as one of the PostScreenMessage's param. If it is small enough (say 0.01s) then you can flood your memory and cause a crash.

As a different way I can suggest GUI.Label method. Just an alternative, not known by me to be quicker, nor safer, nor simpler as you have to use it in a method attached to a PostDrawingQueue, but you can specify a text color.

Link to comment
Share on other sites

ScreenMessageStyle.UPPER_LEFT, or something like that will put the message in that corner, like stock messages.

The problem with using a GUI.Label is that it won't respect other screen messages. The stock function adds each message on a new line. A GUI label will just draw it on top of any other messages. There might be some way of figuring out if other messages are being displayed, how many there are, and how far down you have to move your own label, but that seems like too much trouble. Though I suppose you could just draw your message somewhere else on the screen so that it won't overlap.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...