Hi I am trying to make a chat window for my multiplayer Game. I have done everything except for the fact that the window where the text is placed is always in the top left hand corner of the screen and it is driving me nuts.
Vector2 scrollPosition = new Vector2(5698, 312); // I have put an abstract value here to show that this values does not matter at all and no matter what value I write here it does the same thing.
// and this is the text inside OnGui()
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(450), GUILayout.Height(450));
foreach (var cm in chatHistory)
This bow always ends up being placed in the top left hand corner of the screen and I do not understand why. how can I tell the Scrollview to have a certain x and Y coordinate and a certain width and height.
A ScrollView is also a layouted gui element when you use the GUILayout version. Like any GUILAyout element you never explicitly specify the position. Every element gets it’s position and size from the layoutsystem.
One way is to use a horizontal and a vertical layout group and use a Space before the ScrollView. However that might be a bit too complicated for your case. If you just want to specify where a certain layour group should be positioned you can use
GUILayout.EndArea around your ScrollView. In BeginArea you have to specify a screen rect. Everything between BeginArea and EndArea will be layouted seperately.
The Scroll position only controls the scroll offset of the child objects of the ScrollView. Though you can only scroll when the child objects would overflow the scrollview area. The same way your browser won’t allow any scrolling then the whole website fits onto the screen / window.