Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

My script does not work anymore

Discussion in '2D' started by m121, May 4, 2015.

  1. m121

    m121

    Joined:
    May 4, 2015
    Posts:
    2
    I have used this script and everything worked fine. But now does not work, I can't understand what happened. I think it is an error on Unity. What do you think?


    Code (JavaScript):
    1. #pragma strict
    2.  
    3.      var mainPrefab : GameObject;
    4.      var secondPrefab : GameObject;
    5.      var thirdPrefab : GameObject;
    6.      var fourthPrefab : GameObject;
    7.    
    8.  
    9.  
    10.    
    11.      function OnTriggerEnter2D(other:Collider2D)
    12.     {
    13.     switch( Random.Range(0,4))
    14.     {
    15.             case 01:secondPrefab.transform.position.x = mainPrefab.transform.position.x +(35); secondPrefab.transform.position.y = -1.7; Debug.Log("One");  break;
    16.             case 02:thirdPrefab.transform.position.x = mainPrefab.transform.position.x +(35); thirdPrefab.transform.position.y = -1.7; Debug.Log("Two"); break;    
    17.             case 03:fourthPrefab.transform.position.x = mainPrefab.transform.position.x +(35); fourthPrefab.transform.position.y= -1.7; Debug.Log("three");  break;
    18.          
    19.     }
    20.     }
    21.  
    22.  
    I make a 2D Endless Runner. I want spawn the platform where the character run. But now doesn't work anymore.
     
    Last edited: May 4, 2015
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Please use CODE tag when pasting code and explain more about what is not working and what is expected.
     
  3. Witcher_CA

    Witcher_CA

    Joined:
    May 5, 2015
    Posts:
    19
    Can you explain it , any errors getting while the scene is played ?
     
  4. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    You need to add default: break; in end of your switch.
     
  5. m121

    m121

    Joined:
    May 4, 2015
    Posts:
    2
    while my scene is playing everything is ok. But the script looks like desactivate. I do not know how to explain it. Two weeks ago that script worked perfectly