- Home /
Question by
InvalidSpacebar · Feb 03, 2016 at 11:20 PM ·
c#guiscalingconvertingjava to c#
Converting script to C#
How would you convert this script:
var originalWidth = 640.0;
var originalHeight = 400.0;
private var scale: Vector3;
function OnGUI(){
scale.x = Screen.width/originalWidth; // calculate hor scale
scale.y = Screen.height/originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
GUI.Box(Rect(10,10,200,50), "Box");
GUI.Button(Rect(400,180,230,50), "Button");
GUI.matrix = svMat; // restore matrix
}
into C#? The origonal post: http://answers.unity3d.com/questions/150736/script-gui-units.html
Comment
Best Answer
Answer by brunocoimbra · Feb 04, 2016 at 12:45 AM
Here it is:
public class FileName : MonoBehaviour
{
public float originalWidth = 640.0f;
public float originalHeight = 400.0f;
private Vector3 scale = new Vector3();
private void OnGUI()
{
scale.x = Screen.width / originalWidth; // calculate hor scale
scale.y = Screen.height / originalHeight; // calculate vert scale
scale.z = 1;
var svMat = GUI.matrix; // save current matrix
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
GUI.Box(Rect(10,10,200,50), "Box");
GUI.Button(Rect(400,180,230,50), "Button");
GUI.matrix = svMat; // restore matrix
}
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
GUI box scaling issue [C#] 0 Answers
Multiple Cars not working 1 Answer