Hi
I have created the Unity roll a ball game in Unity 5 as shown in the tutorial section.
The problem I have is when I build the game for deployment for example in web player mode or as a windows game, I build and play the game but the first time you to collect one of the cubes the machine seems to slow down / freeze for a second or so which is noticable. After that collecting cubes is fine but the first time it seems to have a problem. I guess it must be to do with the first time OnTriggerEnter is called but I cant understand why it is having this problem because when I preview the game in Unity I dont have this slow issue.
Can someone advise how this can be fixed as I would like to start creating a game but I need to resolve this before proceeding.
My code is shown here:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private int count;
public GUIText countText;
public GUIText winText;
void start(){
count = 0;
SetCountText ();
winText.text = “”;
}
void FixedUpdate(){
float moveHorizontal = Input.GetAxis (“Horizontal”);
float moveVertical = Input.GetAxis (“Vertical”);
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
GetComponent().AddForce (movement * speed * Time.deltaTime);
}
void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == “PickUp”)
{
other.gameObject.SetActive (false);
count = count +1;
SetCountText ();
}
}
void SetCountText(){
countText.text = "Count: " + count.ToString ();
if (count >= 10) {
winText.text = “You Win!”;
}
}
}
Thanks
Cecilcp