Stuttering in build
Hi
Whilst working on my first project I experienced stuttering issues with the motion of instantiated objects in both the editor and build. I have since resolved the stuttering in editor however when I build and export to my android device the motion is choppy again. In addition to this when the game is first launched some of the animations in the main menu appear choppy but then improve if you revisit the menu from the main game scene which seems kind of strange. Was wondering if anyone could give me any advice or point out any bad habits in my code that could be effecting performance.
Many Thanks :)
Below is the coroutine used to spawn hazards which is called in the start function.
IEnumerator SpawnWalls()
{
yield return new WaitForSeconds(startWait);
while (gameOver == false)
{
velocity += acceleration;
Vector3 spawnPosition = new Vector3(spawnPoint.transform.position.x, 0.5f, spawnPoint.transform.position.z);
Quaternion spawnRotation = Quaternion.identity;
Instantiate(walls[Random.Range(0, walls.Length)], spawnPosition, spawnRotation);
spawnWait = wallSpacing / velocity;
yield return new WaitForSeconds(spawnWait);
}
}
In addition to this here is the script attached to the hazards so that they move with the desired velocity once spawned.
public class mover : MonoBehaviour
{
public GameObject gameController;
private Rigidbody rb;
void Start ()
{
gameController = GameObject.Find("GameController");
rb = GetComponent<Rigidbody>();
float spawnForce = (gameController.GetComponent<GameController>().velocity) * -50f;
rb.velocity = new Vector3(0.0f, 0.0f, -gameController.GetComponent<GameController>().velocity);
}
void FixedUpdate ()
{
if (transform.position.z < -10)
{
Destroy(gameObject);
}
}
}
Your answer
Follow this Question
Related Questions
How can i get a script of a non instantiate prefab? 2 Answers
Android how to wake up the screen when in stand by 1 Answer
Basic Unity: Can someone explain the referencing and instantiation process? 1 Answer
Instantiate a script into an instantiated prefab 3 Answers
Instantiate after loading scene 0 Answers