Hi there, I am using this code to perform some drag and movement features on the iOS. The reason I am posting here is that hopefully someone can help me out (seems like more traffic and this is an overall performance question rather than anything else).
For some reason, this script, which deals with player rotation via a D-Pad, if pressed, over a long period of time (30 seconds) with out a release, will drop fps by 10, frames, then more and more, gradually loosing steam and hovering at about 12fps. I can see no reason why. I am thinking perhaps my use of while(), but ultimately I think garbage collection must be an issue, however I am unsure as to why. Can anyone instruct me as to why this code is terrible for a mobile? * I am looking at Touch now to replace raycast but I was shocked at the performance drop.
function Update()
{
if (Input.GetMouseButtonUp(0)){
///CANCEL THE ABILTY TO FIRE (* handled in determineInputMethod())
pressingDown = false;
}
else if (Input.GetMouseButton(0)){
theTouch =Input.mousePosition;
ray = cam.ScreenPointToRay(theTouch);
if (Physics.Raycast(ray, hit)){
if (hit.collider == thisCollider){
pressingDown = true;
handleInputMethod();
return;
}
}
}
}
function handleInputMethod()
{
while(pressingDown){
handleRotation();
yield;
}
}
function handleRotation()
{
///gather rise and run of input pos with centerNodePos
inputPos = Input.mousePosition;
targetNodePos = cam.ScreenToWorldPoint(inputPos);
targetNode.position = Vector3(targetNodePos.x, targetNodePos.y, -40);
targetNodePosLocal = targetNode.localPosition;
centerNode.LookAt(targetNode);
brain.rotation = centerNode.localRotation;
if(targetNodePosLocal.x < 0){////face brain left
if(brain.localScale.x != -1){
brain.localScale.x = -1;
brainLocalScale = -1;
}
}
else if(targetNodePosLocal.x > 0){////face brain left
if(brain.localScale.x != 1){
brain.localScale.x = 1;
brainLocalScale = 1;
}
}
yield;
}