- Home /
Question by
mabit · Jun 01, 2012 at 05:28 PM ·
fpsslowmain thread
FPS issues
Any help here would be great.
My game is dropping down to 2 FPS with very little happening. My PC is i7, 8GB Ram and 1GB GFX Card. And my Android Device is a Dual Core 1GB processor.
However when I run the game on both machines the games FPS falls to the point the game breaks.
This is the script that each object is running which does not seem like it would cause problems. One the game gets to approx 20 objects its slowing down, by mid 30's unplayable.
#pragma strict
var poisonSmoke:GameObject;
var maleMouse:GameObject;
var femaleMouse:GameObject;
var newDirection:int;
var canCollide:boolean = true;
var moveSpeed:int=5;
var isShagging:boolean = false;
var gender:int;
var poisoned:boolean = false;
function Start () {
gameObject.name = "Baby Mouse";
GameVariables.numberOfMiceAlive++;
GrowUp();
}
function Update () {
transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
var hit : RaycastHit;
var forwardRay = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, forwardRay * 6, Color.magenta);
if(Physics.Raycast(transform.position, forwardRay, hit, 6)){
Debug.Log("Hit");
if(hit.collider.gameObject.tag == "Hedge" || hit.collider.gameObject.tag == "Brick Wall"){
newDirection = Random.Range(0,4);
Debug.Log (transform.eulerAngles.y);
switch (newDirection){
case 0:
transform.eulerAngles = Vector3(0, 90, 0);
break;
case 1:
transform.eulerAngles = Vector3(0, 180, 0);
break;
case 2:
transform.eulerAngles = Vector3(0, 270, 0);
break;
case 3:
transform.eulerAngles = Vector3(0, 0, 0);
break;
}
}
}
if(Physics.Raycast(transform.position, forwardRay, hit, 6)){
Debug.Log("Hit");
if(hit.collider.gameObject.tag == "Hedge" || hit.collider.gameObject.tag == "Brick Wall"){
newDirection = Random.Range(0,4);
Debug.Log (transform.eulerAngles.y);
switch (newDirection){
case 0:
transform.eulerAngles = Vector3(0, 90, 0);
break;
case 1:
transform.eulerAngles = Vector3(0, 180, 0);
break;
case 2:
transform.eulerAngles = Vector3(0, 270, 0);
break;
case 3:
transform.eulerAngles = Vector3(0, 0, 0);
break;
}
}
}
if(Physics.Raycast(transform.position, forwardRay, hit, 0.1)){
if(hit.collider.gameObject.tag == "Rotate Spot"){
newDirection = Random.Range(0,4);
Debug.Log("new dir = " +newDirection);
Debug.Log (transform.eulerAngles.y);
switch (newDirection){
case 0:
transform.eulerAngles = Vector3(0, 90, 0);
break;
case 1:
transform.eulerAngles = Vector3(0, 180, 0);
break;
case 2:
transform.eulerAngles = Vector3(0, 270, 0);
break;
case 3:
transform.eulerAngles = Vector3(0, 0, 0);
break;
}
}
if (hit.collider.gameObject.tag == "Poison"){
Destroy(gameObject);
GameVariables.numberOfMiceAlive--;
}
if (hit.collider.gameObject.tag == "Toxic Gas"){
Destroy(gameObject);
GameVariables.numberOfMiceAlive--;
}
if (hit.collider.gameObject.tag == "Bomb Explosion"){
Destroy(gameObject);
GameVariables.numberOfMiceAlive--;
}
}
}
function GrowUp(){
if (!poisoned){
yield WaitForSeconds(10);
gender = Random.Range(0,2);
if(gender == 0){
Instantiate (maleMouse, Vector3(transform.position.x,transform.position.y, transform.position.z) , Quaternion.identity);
Destroy(gameObject);
}
if (gender == 1){
Instantiate (femaleMouse, Vector3(transform.position.x,transform.position.y, transform.position.z) , Quaternion.identity);
Destroy(gameObject);
}
GameVariables.numberOfMiceAlive--;
}
}
Comment
Best Answer
Answer by Eric5h5 · Jun 01, 2012 at 05:53 PM
Take the Debug.Logs out.
Thanks, I didn't realise they slowed things down so much. Can now get over 100 objects on screen before it slows down....Thanks for the quick answer :)