Where would I put this bit of code?

Hello. Someone gave me this code to fix a GUI/resolution problem in my game. It takes the resolution that I developed my game in and scales the positions so that it will look correct at any resolution(I foolishly placed my GUI elements using absolute pixel positions). My problem is, I don’t know where to put the code. Do I put it in every GUI function?

*Vetor3 scale = new Vector3(origWidth
*/Screen.width, origHeight /
*Screen.height, 1); GUI.matrix
*=Matrix4x4.Scale(scale);

try putting it in every GUI function and see if it works if so then yes ok

Okay. That didnt work, so where do I put the code?

You put it at the start of every OnGUI() function on any script that has one.

That said, your code doesn’t seem to declare what origWidth origHeight is supposed to be so made sure you declare that in your scripts and have them se correctly.

Maybe go back to the person that gave you this code and ask them about how to implement it if you are having trouble.

Here is the code, and I am getting several errors

function OnGUI () {
	*Vetor3 scale = new Vector3(1024
	*/Screen.width, 768 /
	*Screen.height, 1); GUI.matrix
	*=Matrix4x4.Scale(scale)	
	GUI.skin = mySkin;
    toolbarInt =   GUI.Toolbar (Rect (35, 110, 900, 30), toolbarInt, toolbarStrings);}

Syntax is a bit messed up with the slashes. I guess the person you’re copying from meant something like this?

Vetor3 scale = new Vector3(1024 * Screen.width, 768 *S creen.height, 1);
GUI.matrix *= Matrix4x4.Scale(scale);
GUI.skin = mySkin;

Try getting rid of those '*'s :slight_smile: They aren’t part of the code.

Also, it is C# and it appears you are adding it to JavaScript.

EDIT: I also noticed: Vetor3 scale
It should be Vector3 scale

Good pickups Dman, don’t know how I missed the JavaScript/C# mixup… again!

Thanks everyone for your help, how would this code look in JS?

Tofudude624, read through this tutorial and make an attempt: http://forum.unity3d.com/threads/34015-Newbie-guide-to-Unity-Javascript-(long)

If you still cannot write the JavaScript, feel free to ask us specific questions about the issues at hand.

Okay, I got that piece of code working with no errors, but I have a (new?) problem. The camera in my game gets distorted, its as if it is moved out(the GUI textures are all still displaced), any ideas?

Anyone have any ideas as to why the camera is being distorted?