Hello, i was wondering how i would print player transform to log with text? like for example:
Debug.LogFormat("Player Position:",transform.position.ToString);//doesn't work for some reason
print(transform.position.y);//works
print(transform.position.z);//works
Indeed. If itâs being printed very frequently, I personally try to keep those to a minimum and for only certain tests. Infrequent, I donât mind either way, while debugging; if the info is helpful in some way, thatâs all I need.
Just remove it when itâs no longer needed.
How would i make it so that it opens when i click GUI button? i have this debug menu here, which would be great idea to to use to print it: https://prnt.sc/i13euu And also how would i open and close GUI box with its contents from a button of a keyboard like the tilde key? Sorry if it goes a bit out of topic, next time i make new topics if i have more questions.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
private bool isDrawingDebugMenu = false;
// When enter is pressed, invert the boo, True
// becomes false and vice verse
private void Update(){
if(Input.GetKeyDown(KeyCode.Enter))
isDrawingDebugMenu = !isDrawingDebugMenu;
}
private void OnGUI(){
// if isDrawingDebugMenu is false, return early so the menu isnt drawn
if(isDrawingDebugMenu == false)
return;
// Menu code down here
}
}
Hand written so may have a syntax error somewhere.
Or, if its a GUI button which hides the menu I think it would be:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
private bool isDrawingDebugMenu = false;
// When enter is pressed, invert the boo, True
// becomes false and vice verse
private void Update(){
if(Input.GetKeyDown(KeyCode.Enter))
isDrawingDebugMenu = true;
}
private void OnGUI(){
// is isDrawingDebugMenu is false, return early so the menu isnt drawn
if(isDrawingDebugMenu == false)
return;
if(GUI.Button(/* Some Params */))
isDrawingDebugMenu = false;
// Menu code down here
}
}
Alright, thanks that worked very well. Would you know how to change the exact button text color to like yellow when its enabled not like this: http://prntscr.com/i16v81 where it turns all buttons and texts to the same color.
And also how would i make it so that the game pauses when menu is opened and stays paused until menu is closed and prints some text box to screen saying game is paused or something.
If that is for in-game, Iâd suggest that you use UGUI. You can find these/this by the âCreateâ menu â UI â (panel , text, etcâŚ). Much more widely used, and talked about on the forums.
My knowledge of OnGUI stuff is limited, but you can search the manual.
One way to pause the game is to set the timeScale to zero. If you do that, remember to set it back to â1â when you unpause. Adding text to the screen can be done with the UGUI mentioned above and creating a âTextâ game object
If you really wanna go with that legacy UI system, you would cache the current color, set a new color, draw the tinted elements and set the old color again before the next UI elements that need to be rendered using the old color.
//semi-pseudo code
DrawSomeNormalElements(); // renders with default color
previousColor = GUI.color; // cache the current color
GUI.color = yourTintColor; // set the new color, everything that follows will now be colored
DrawColoredElements(); // some UI elements
GUI.color = previousColor; // set the color you cached previously
DrawSomeOtherNormalElements(); // render some more UI elements using the old color
There are also gui styles and skins for the legacy system, but seriously, if you want to implement not just plain, simple, quick and temporary UI, youâre better off using the new system. Itâs much more convenient, easier to setup and configure.
Pausing has already been mentioned, just a little side note: everything that shouldnât be paused must not be dependant on that time scale (either not time dependant at all or it needs to rely on the unscaled time values). There should actually be quite alot of examples out there. Just grab one and play with it just a little bit.