- Home /
spawned object wont change scale?
hey guys, im trying to spawn an object that continues to scale on one axis to match a distance between 2 points. now i know the calculation of the distance works fine as ive found out with debug. my issue is when the object spawns it does have the right value on the x axis, however as the distance gets larger the spawned object stays the same, what i want is the object to get larger every frame as the distance gets larger. also a 2nd issue is the object is pawning with values of 0 on both y and z axis, where i needed them on at least a scale of 1, i cant figure out why =S
here is the small bit of code (lines 194 to 203) which is my update section
void Update()
{
Debug.Log (dragDistance);
Vector3 temp = ArrowPrefab.transform.localScale;
temp.z = dragDistance;
ArrowPrefab.transform.localScale = temp;
}
full code can be seen here>>> http://codeviewer.org/view/code:36f5
any help would be great. thankyou
Answer by Visual Programmer · Sep 30, 2013 at 12:05 AM
Convert this to C# and I think this will be what you need. You'll want to make sure the object is rotated in the right direction and that maxScale is the distance/2 of what you need. you can set scale to whatever you want the change rate of the objects' scale to be. And don't forget to scale the correct axis.
var upScale:float = 0.5;
var scale:float = 1.0;
var maxScale:float = 20.0;
private var scaling:Vector3 = Vector3(1, 1, 1);
function Update(){
if(scale < maxScale){
scale += upScale * Time.deltaTime;
scaling.y = scale;
}
this.transform.localScale = scaling;
}