Search Unity

Unity editor - Game testing not working propertly

Discussion in 'Editor & General Support' started by PAVAPROJECTS, Jan 21, 2019.

  1. PAVAPROJECTS

    PAVAPROJECTS

    Joined:
    Jan 21, 2019
    Posts:
    4
    So I have been working for Unity for over a month now ... and I was getting frustrated because I was following lessons step by step. When I tested the game using the "Play" button to test my progress and using my Oculus Riff, sometimes the game will work as expected, but sometimes it stopped working like this last lesson and the Raycaster hit test function.

    At this point, I have no errors only log. and everything stops working out of the blue

    But .... hahahah ..... I decided to compile the game and create an executable and test and game works as expected.

    Any ideas on why this is happening?

    I am using Unity 2018.3.0f2 and VB 15.9.5


    Thanks in advance

    I copy the simple code I am working with

    Note: I am using the Google GvrRecticlePointer In the camera and GVrEditorEmulator for the test window


    [1]: /storage/temp/131601-code.txt
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine.SceneManagement;
    3. using UnityEngine;
    4.  
    5. public class GameComtroller : MonoBehaviour
    6. {
    7.     public Camera gameCamera;
    8.     public GameObject target;
    9.     public float stareDuration = 1f;
    10.     public float targetDistance = 5f;
    11.     public TextMesh infoText;
    12.     public float gameDuration = 5f;
    13.  
    14.     private float stareTimer;
    15.     private float hits;
    16.     private float gameTimer;
    17.  
    18.  
    19.     // Start is called before the first frame update
    20.     void Start(){
    21.         stareTimer = 0f;
    22.         gameTimer = 10f;
    23.         MoveCube();
    24.              
    25.     }
    26.  
    27.     // Update is called once per frame
    28.     void Update(){
    29.  
    30.         RaycastHit hit;
    31.         if(Physics.Raycast(gameCamera.transform.position, gameCamera.transform.forward, out hit))
    32.         {
    33.             if (hit.transform.name == "Target")
    34.             {
    35.                 ////Debug.Log("Hit Target!");
    36.                 stareTimer += Time.deltaTime;
    37.             }else{
    38.                 stareTimer = 0f;
    39.             }
    40.         }
    41.  
    42.  
    43.         //check if its time to teleport
    44.         if(stareTimer >= stareDuration && gameTimer >= 0f)
    45.         {
    46.             Debug.Log(hits);
    47.             stareTimer = 0f;
    48.             hits ++;
    49.  
    50.             MoveCube();
    51.  
    52.         }
    53.  
    54.          gameTimer -= Time.deltaTime;
    55.  
    56.  
    57.         if (gameTimer >= 0f){
    58.             infoText.text = "Hits: " + hits;
    59.             infoText.text += "\nTimes: " + Mathf.Floor(gameTimer);
    60.         }else{
    61.                 infoText.text = "GameOver!\n Your Score:" + hits;
    62.                 infoText.text = "\nPress R to restart" ;
    63.  
    64.               if (gameTimer < -3f){
    65.                  SceneManager.LoadScene (SceneManager.GetActiveScene().name);
    66.               }
    67.        }
    68.  
    69.     }
    70.  
    71.     void MoveCube(){
    72.  
    73.         float randomAngle = Random.Range(0, 2 * Mathf.PI);
    74.         target.transform.position = new Vector3(
    75.             Mathf.Cos(randomAngle) * targetDistance,
    76.             Random.Range(0, targetDistance),
    77.             Mathf.Sin(randomAngle) * targetDistance
    78.             );
    79.     }
    80. }
    81.  
     

    Attached Files:

  2. annoying_brother

    annoying_brother

    Joined:
    May 22, 2020
    Posts:
    1
    I don't see any problems but my unity just stops working when I click test so oof. Look on unity profiler to see what is causing the problem script or models!