I have a prefab that I instantiate 10 seconds after loading the level. The Script is a generic mover script which as you can see will not run as default. Then I have a separate scrip to instantiate the object which works correctly and assign targetA and targetB which normally would be done in inspector but the two targets are also instantiated objects that are made before my prefab with mover script. When I run this the script runs and everything but for some reason the main thread spike to 516-520milisecond response time dropping FPS in game from 120ish to 1.5ish. Can anyone explain/help me with this? Link below for video to show this....
//code 1
#pragma strict
var targetA : GameObject;
var targetB : GameObject;
var setter : boolean = false;
var speed : float = 0.1;
function FixedUpdate ()
{
if(setter) {
var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5; transform.position = targetA.transform.position * weight + targetB.transform.position * (1-weight);
}
}
//code 2
myobject = Instantiate(moverprefab, Vector3(1025.872, 41.44104, 2492.541),Quaternion.Euler(0,29.22,0-16.8));
var theScript = myobject.GetComponent(lvl4padmover);
theScript.targetA = top.gameObject;
theScript.targetB = bottom.gameObject;
theScript.setter = true;
[link text][1]
[1]: http://www.youtube.com/watch?v=CF9_sjazgBs
↧