Hello,
well now i’m left the design stage of my project and now it comes to optimization…
There are so different opinions and approaches that can be really confusing…
So here is my first Question :
I have a Update function in my Script that looks like :
function Update() {
if (!SpaceShip)
SpaceShip = GameObject.FindWithTag("SpaceCraft");
if(SpaceShip) {
if (pause == false){
UpdateAttitude (SpaceShip.transform); //Richtungszeiger
HealthLevelerTransform.rotation.eulerAngles.z = 90.0 + SpaceShip.transform.rotation.eulerAngles.z;
ShipRotX = 0.5 + SpaceShip.transform.rotation.x; //Neigung
RadarCompassTransform.rotation.eulerAngles.z = SpaceShip.transform.rotation.eulerAngles.y;
var hit : RaycastHit;
if (Physics.Raycast (SpaceShip.transform.position, -Vector3.up, hit)) {
GroundDistance = hit.distance;
if (GroundDistance < 10.0) {
GroundWarning = true;
} else {
GroundWarning = false;
}
}
}
if (! Cam1)
Cam1 = GameObject.FindWithTag ("MainCamera");
if (!Cam1Audio)
Cam1Audio = Cam1.GetComponentInChildren(AudioListener);
if (! Cam3)
Cam3 = GameObject.Find ("GUI");
if (!Cam2)
Cam2 = SpaceShip.GetComponentInChildren(Camera);
//Cam2 = GameObject.FindWithTag("ShakeCam").GetComponent(Camera);
if (!Cam2Audio)
Cam2Audio = SpaceShip.GetComponentInChildren(AudioListener);
if (! ShipLight)
ShipLight = SpaceShip.Find("Pointlight");
if (! Follow)
Follow = SpaceShip.GetComponentInChildren(FollowTransform);
So because i Spawn my Player i have this GO find stuff… but that’s only @ beginning of the Game…
I hope i can change it later and connect it with my Spawn Pool so that there is no GO find function…
But for the Rest it looks to me that it doesn’t have to be in a update function…
So i did this :
public var targettingFrequency : float = 1.2f;
public var trajectoryFrequency : float = 0.2f;
public var trajectoryBlend : float = 1.0f;
private var updatedTrajectory : Vector3 = Vector3.zero;
private var currentTrajectory : Vector3 = Vector3.zero;
function Start (){
InvokeRepeating("DoTargetting", targettingFrequency*Random.value, targettingFrequency);
InvokeRepeating("DoTrajectory", trajectoryFrequency*Random.value, trajectoryFrequency);
DoTargetting();
DoTrajectory(); }
function Update () {
currentTrajectory = Vector3.Lerp(currentTrajectory, updatedTrajectory, Time.deltaTime * trajectoryBlend);
radarRotation.z = radarRotation.z + rotateSpeed * Time.deltaTime;
RadarZeigerTransform.rotation.eulerAngles.z = radarRotation.z;
}
function DoTargetting() {
// search for targets here, we don't do it often because it's expensive
if (!SpaceShip)
SpaceShip = GameObject.FindWithTag("SpaceCraft");
if (! Cam1)
Cam1 = GameObject.FindWithTag ("MainCamera");
if (!Cam1Audio)
Cam1Audio = Cam1.GetComponentInChildren(AudioListener);
if (! Cam3)
Cam3 = GameObject.Find ("GUI");
if (!Cam2)
Cam2 = SpaceShip.GetComponentInChildren(Camera);
//Cam2 = GameObject.FindWithTag("ShakeCam").GetComponent(Camera);
if (!Cam2Audio)
Cam2Audio = SpaceShip.GetComponentInChildren(AudioListener);
if (! ShipLight)
ShipLight = SpaceShip.Find("Pointlight");
if (! Follow)
Follow = SpaceShip.GetComponentInChildren(FollowTransform);
}
function DoTrajectory() {
// trajectory isn't as expensive but it's not something we need to do every frame
if(SpaceShip) {
if (pause == false){
UpdateAttitude (SpaceShip.transform); //Richtungszeiger
HealthLevelerTransform.rotation.eulerAngles.z = 90.0 + SpaceShip.transform.rotation.eulerAngles.z;
ShipRotX = 0.5 + SpaceShip.transform.rotation.x; //Neigung
RadarCompassTransform.rotation.eulerAngles.z = SpaceShip.transform.rotation.eulerAngles.y;
var hit : RaycastHit;
if (Physics.Raycast (SpaceShip.transform.position, -Vector3.up, hit)) {
GroundDistance = hit.distance;
if (GroundDistance < 10.0) {
GroundWarning = true;
} else {
GroundWarning = false;
}
}
}
}
My Question is : Makes this optimization sense ? There is no big difference in the fps if i do that.
Is invoke Repeating the same as StartCoroutine ? Where is the difference ? The Doc’s are not really helpful and if you look @ the AngryBots demo
there is like noooo Optimization… all is done in Update also Raycast and simple Texture Animation… So i think i can’t learn from it how to optimize my Game…
Also many People here say (maybe Wrong):
function DoSomething (someParameter : float) {
while (true) {
print("DoSomething Loop");
// Yield execution of this coroutine and return to the main loop until next frame
yield;
}
}
The Coroutine should be better for Performance than Update… that’s not true i think if you run it only with yield… than it run’s also every frame and has the same perf. impact as a Update function or ?
So thank you to take the time to lighten me up what the best Performance way is…