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. Dismiss Notice

Can't Add Script JavaScript

Discussion in 'Editor & General Support' started by EdgarCarrera, Jun 12, 2014.

  1. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    look the Thumbnail i got error later importing script to emty object.
     

    Attached Files:

    • 2.jpg
      2.jpg
      File size:
      252.2 KB
      Views:
      813
  2. Hikiko66

    Hikiko66

    Joined:
    May 5, 2013
    Posts:
    1,300
    Does the class name match the file name?
     
  3. EdgarCarrera

    EdgarCarrera

    Joined:
    Apr 21, 2014
    Posts:
    255
    My all Script.

    Code (JavaScript):
    1. @script ExecuteInEditMode()
    2.  
    3. var gameName : String = "Mattsgamesfortesting";
    4.  
    5. var refreshing = false;
    6. var hostData : HostData[];
    7.  
    8. var create = false;
    9. var joining = false;
    10.  
    11. var serverName = "";
    12. var serverInfo = "";
    13. var serverPass = "";
    14.  
    15. var playerName = "";
    16.  
    17. var clientPass = "";
    18.  
    19. //var scrollPosition = "";
    20.  
    21. var scrollPosition : Vector2 = Vector2.zero;
    22.  
    23. function Start(){
    24.  
    25.     playerName = PlayerPrefs.GetString("Player Name");
    26. }
    27.  
    28. function OnGUI(){
    29.  
    30.     if(!Network.isClient && !Network.isServer){
    31.  
    32.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2,100,20),"Create Game")){
    33.  
    34.             create = true;
    35.         }
    36.  
    37.         if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/2 + 30,100,20),"Create Game")){
    38.  
    39.             joining = true;
    40.             refreshHostList();
    41.         }
    42.     }
    43.  
    44. if(create){
    45.  
    46.     if(GUI.Button(Rect(Screen.wigth/2 - 50,Screen.height/3 + 110,100,50),"Create")){
    47.  
    48.         startServer();
    49.     }
    50.  
    51.     GUI.Label(Rect(Screen.width/2 - 110,Screen.height/3,100,20),"Server Name:");
    52.     GUI.Label(Rect(Screen.width/2 + 40,Screen.height/3,100,20),"Password:");
    53.     GUI.Label(Rect(Screen.width/2 - 30,Screen.height/3 + 90,100,20),"Server Info:");
    54.  
    55.     serverName = GUI.TextField (Rect(Screen.width/2 - 120,Screen.height/3 + 30, 100, 20),serverName, 12);
    56.     serverPass = GUI.PasswordField (Rect(Screen.width/2 + 20,Screen.height/3 + 30, 100, 20),serverPass, "*"[0], 12);
    57.     serverInfo = GUI.TextField (Rect(Screen.width/2 - 70,Screen.height/3 + 30, 150, 20),serverInfo, 12);
    58.  
    59.     if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    60.  
    61.         create = false;
    62.     }
    63.  
    64.     if(joining){
    65.  
    66.         if(hostData){
    67.  
    68.             scrollPosition = GUI.BeginScrollView (Rect(Screen.width/4,Screen.height/6,Screen.width/1.5,Screen.height/2),scrollPosition, Rect(0, 0, 300, 1000/*hostData.Length * 30*/));
    69.            
    70.             GUI.Label(Rect(30,0,100,20),"Game Name");
    71.             GUI.Label(Rect(350,0,100,20),"Server Info");
    72.             GUI.Label(Rect(590,0,100,20),"Player Count");
    73.             GUI.Label(Rect(700,0,100,20),"Password");
    74.  
    75.             for (var i:int = 0; i < hostData.length; i++){
    76.  
    77.                 GUI.Label(Rect(0,30 + i * 30,200,22),hostData[i].gameName);
    78.                 GUI.Label(Rect(160,30 + i * 30,500,22),hostData[i].comment);
    79.                 GUI.Label(Rect(640,30 + i * 30,100,22),hostData[i].connectedPlayers + " / " + hostData[i].playerLimit);
    80.  
    81.                 if(hostData[i].passwordProtected){
    82.  
    83.                     clientPass = GUI.PasswordField(Rect(680, 30 + i * 30, 100, 25), clientPass, "*"[0], 12);
    84.                 }
    85.  
    86.                 if(GUI.Button(Rect(800, 30 + i * 30, 100, 25), "Join")){
    87.                    
    88.                     Network.Connect(hostData[i], clientPass);
    89.                 }
    90.             }
    91.             GUI.EndScrollView();
    92.         }
    93.  
    94.         if(!hostData){
    95.  
    96.             GUI.Label(Rect(Screen.width/2 - 50,Screen.height/3,200,25), "No Games Found");
    97.  
    98.             if(GUI.Button(Rect(Screen.width/2 - 50,Screen.height/3 + 30,105,25),"Refresh")){
    99.                 refreshHostList();
    100.             }
    101.         }
    102.        
    103.         if(GUI.Button(Rect(Screen.width/1.2,Screen.height/20,100,20),"Back")){
    104.  
    105.             joining = false;
    106.         }
    107.     }
    108.  
    109.         if(GUI.Button(Rect(Screen.width/20,Screen.height/20,100,20),"Quit")){
    110.  
    111.             Application.Quit();
    112.         }
    113.  
    114.         GUI.Label(Rect(Screen.width/2 - 35,Screen.height/1.2 - 30,100,20),"Your Name:");
    115.         playerName = GUI.TextField(Rect(Screen.width/2 - 50,Screen.height/1.2,100,20), playerName, 12);
    116.         }
    117.     }
    118.  
    119.     function Update (){
    120.  
    121.         if(refreshing){
    122.  
    123.             if(MasterServer.PollHostList().Length > 0){
    124.  
    125.                 refreshing = false;
    126.                 hostData = MasterServer.PollHostList();
    127.             }
    128.         }
    129.     }
    130.  
    131.     function startServer(){
    132.  
    133.         if(serverPass != ""){
    134.  
    135.             Network.incomingPassword = serverPass;
    136.         }
    137.  
    138.         Network.InitializedServer(15,25001, !Network.HavePublicAddress);
    139.         MasterServer.RegisterHost(gameName,serverInfo);
    140.     }
    141.  
    142.     function OnServerInitialized(){
    143.  
    144.         DontDestroyOnLoad(transform.gameObject);
    145.  
    146.         Application.LoadLevel ("Lobby");
    147.  
    148.         lobbySpawn();
    149.     }
    150.  
    151.     function OnConnectedToServer(){
    152.  
    153.         lobbySpawn();
    154.     }
    155.    
    156.     function lobbySpawn(){
    157.  
    158.         yield WaitForSeconds(0.1);
    159.  
    160.         var made = Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
    161.  
    162.         made.GetComponent(playerMove).playerName = playerName;
    163.  
    164.         PlayerPrefs.SetString("Player Name", playerName);
    165.  
    166.         if(Network.isClient){
    167.  
    168.             Destroy(this);
    169.         }
    170.     }
    171.  
    172.     function refreshHostList(){
    173.  
    174.         MasterServer.ClearHostList();
    175.         MasterServer.RequestHostList(gameName);
    176.         refreshing = true;
    177.     }
     
  4. ElvisAlistar

    ElvisAlistar

    Unity Technologies

    Joined:
    Oct 2, 2013
    Posts:
    226
    Your networkView.js script has some compilation errors. Fix all compilation errors before attempting to attach scripts to GameObjects.