First of all, Hello
I followed the community boards for some time and until now it was always helpfull, thx for the work @ the guys investing hours to answer all the questions here!
Now I have a problem with my iphone app i want to realize.
I have a szene where are multiple objects in that can be draged around, rotated and scaled.
You can click on an object an drag it arround, which works perfectly, the same with the rotation.
Now the scaling of the objects should be the same for all the objects in the Scene, so if I get 2 Touch inputs I create an buildin array by calling the Find by Tag. (Just if Input.GetTouch(1).phase == TouchPhase.Began so i dont call a search function every frame.)
If the change of the “Input Vector” direction behaves like a rotation, the object rotates, which works.
If the magnitude of the Vector becomes longer or shorter then a certain percentage of the “Start Input Vector” all the objects should get scaled.
private var toscale: GameObject[];
private var startdist: Vector2;
private var scalestart: float;
// Its a little more complicated because of the other possibility to rotate, but the simplified version should work for understanding
if ( 2 Inputs and secondinput.phase = InputPhase.Began) {
toscale = GameObject.FindGameObjectsWithTag("sometag");
scalestart = toscale[0].transform.localScale.x;
startdist = (inputPos1 - inputPos2);
}
if (scale) {
var skalevalue: float = (inputPos1 - inputPos2).sqrMagnitude/startdist.sqrMagnitude;
skalevalue = scalestart*skalevalue;
var skalevector: Vector3 = Vector3.Lerp(toscale[0].transform.localScale, Vector3(skalevalue, skalevalue, skalevalue), 0.2);
for (var s: int =0; s < toscale.length; s++) {
toscale[s].transform.localScale = skalevector;
}
}
The objects that i want to get scaled consist mostly of 3 objects, a parent with a simple meshcollider to get a raycasthit to drag the object arround. And 2 childs, a semitransparent shadowplane and the solid object itself.
Now my problem is, at the moment i try to scale the objects my frame-rate drops from fluent to 1 or 2 frames.
Is rescaling objects so expensive? Or is my code just crap?
Puting all my objects in a parent object and rescaling the parent is a possibility but its not the best one, because they also chance position when rescaling just 1 holder-object with all my objects in and would it be less expensive or not?
What would be the best possibility to rescale them? any idea?