Hi,
I have 200+ objects and I call this script in update function. This decreases my performance a lot.
Is there a way how to write it better?
I am in 2D.
void rotateObject(Vector3 rotationTarget, int angleDifference)
{
Vector3 targetVector = rotationTarget - myTransform.position;
float angle = Mathf.Atan2(targetVector.y, targetVector.x) * Mathf.Rad2Deg - angleDifference;
q = Quaternion.AngleAxis(angle, Vector3.forward);
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, q, Time.deltaTime * myRotationSpeed);
}
↧