Hi, I'm new to Unity and trying to scale a cube with the GUI. I've found this script: Code (csharp): /* Using nested Horizontal and Vertical Groups */ var sliderValue = 1.0; var maxSliderValue = 10.0; function OnGUI() { // Wrap everything in the designated GUI Area GUILayout.BeginArea (Rect (0,0,200,60)); // Begin the singular Horizontal Group GUILayout.BeginHorizontal(); // Place a Button normally if (GUILayout.RepeatButton ("Increase max\nSlider Value")) { maxSliderValue += 3.0 * Time.deltaTime; } // Arrange two more Controls vertically beside the Button GUILayout.BeginVertical(); GUILayout.Box("Slider Value: " + Mathf.Round(sliderValue)); sliderValue = GUILayout.HorizontalSlider (sliderValue, 0.0, maxSliderValue); // End the Groups and Area GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndArea(); } How do I use the "sliderValue" for scaling e.g. the x-axis of a cube? I guess it's the update function but I have no idea how to tell the slide to sclae the cube. Greetings
There are several ways to do it. You can put a script on the cube, for example, that queries sliderValue. Or you could add: Code (csharp): public var object : GameObject; In front and then do something like: Code (csharp): object.transform.scale.x = sliderValue; object.transform.scale.y = sliderValue; object.transform.scale.z = sliderValue; Not sure about the exact syntax. You will also want to performance-optimize this by calling it only when sliderValue actually changed. But you get the idea?