Solved this on my own
Stuck with scaling an object
I've been trying to scale an object using its x,y,z axis using a slider. However, I have a problem trying to use 3 different sliders for each axis (x for length, y for width, and z for height). The problem is that only one slider works (which the only thing that scales is the height) in the code that I've done even though I've declared 3 sliders to perform a transform function for each axis. Can someone please tell me what's wrong and how to debug something like this? I've very new in unity. Thanks :)
Here's the code that I used on my sliders
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScaleSlider : MonoBehaviour {
public Slider sliderLength;
public Slider sliderWidth;
public Slider sliderHeight;
// Use this for initialization
void Start () {
sliderLength.value = 1;
sliderWidth.value = 1;
sliderHeight.value = 1;
}
// Update is called once per frame
void Update () {
transform.localScale = new Vector3 (sliderLength.value*1f, 1, 1);
transform.localScale = new Vector3 (1, sliderWidth.value*1f, 1);
transform.localScale = new Vector3 (1, 1, sliderHeight.value*1f);
}
}
Answer by Cynikal · Nov 03, 2016 at 02:35 PM
private float X = 0f;
private float Y = 0f;
private float Z = 0f;
void Update()
{
X = sliderLength.value;
Y = sliderWidth.value;
Z = sliderHeight.value;
transform.localScale = new Vector3(X, Y, Z);
}
Follow this Question
Related Questions
Gradually editing the scale of an object 1 Answer
Scaling material without saving scale on original material 1 Answer
Scaling Challenge Help Needed! 0 Answers
2D Mobile GUI Scaler 1 Answer
Problem : Scale Object by distance 0 Answers