Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by adriano back · Aug 03, 2014 at 12:25 AM · errorrpcindexoutof

helpme RPC

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class NetworkManager : MonoBehaviour
 {
     private string MSName = "SurvivorV2020_16123";
     private HostData[] hostData;
 
     public GameObject[] Maps;
     public GameObject[] Characters;
     public static GameObject myPlayer;
 
     private int map;
     private int character;
 
     public static string Name = "";
 
     public List<string> Jogadores = new List<string>();
 
     //Administraçao de salas
     void NovaSala()
     {
         Network.InitializeServer(16, 21022, !Network.HavePublicAddress());
         MasterServer.RegisterHost(MSName, "ServerTest");
         Debug.Log("Server Criado.");
     }
     void Actualizar()
     {
         MasterServer.RequestHostList(MSName);
         hostData = MasterServer.PollHostList();
     }
 
     //Spawn de mapas e jogadores
     void Spawn(int mapa, int jogador)
     {
         myPlayer = Network.Instantiate(Characters[jogador], new Vector3(0, 2, 0), Quaternion.identity, 0) as GameObject;
         Instantiate(Maps[mapa], new Vector3(0, 0, 0), Quaternion.identity);
     }
 
     //Eventos
     void OnConnectedToServer()
     {
         //Spawn(0, 0);
         networkView.RPC("addPlayer", RPCMode.AllBuffered, Name);
     }
     void OnServerInitialized()
     {
         //Spawn(0, 0);
         networkView.RPC("addPlayer", RPCMode.AllBuffered, Name);
     }
     void OnDisconnectedFromServer()
     {
         Network.Destroy(myPlayer);
     }
 
     //UI do jogo
     void OnGUI()
     {
         if (Network.isClient || Network.isServer)
         {
             Lobby();
             return;
         }
 
         Actualizar();
         GUILayout.BeginArea(new Rect(5, 5, Screen.width - 10, Screen.height - 10), "", "box");
         GUILayout.BeginHorizontal();
         {
             if (GUILayout.Button("Nova Sala"))
                 NovaSala();
             Name = GUILayout.TextField(Name, GUILayout.Width(200));
             if (GUILayout.Button("Aplicar"))
             {
                 networkView.name = Name;
             }
         }
         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal("box");
         {
             if (hostData != null)
             {
                 foreach (HostData sala in hostData)
                 {
                     GUILayout.Label(sala.gameName + sala.connectedPlayers);
                     if (GUILayout.Button("Connect"))
                         Network.Connect(sala);
                 }
             }
         }
         GUILayout.EndHorizontal();
         GUILayout.EndArea();
     }
     void Lobby()
     {
         if (PlayerController.isSpawned) return;
         GUILayout.BeginArea(new Rect(5, 5, (Screen.width / 2) - 5, Screen.height - 10), "", "box");
         {
             foreach(string jogador in Jogadores)
             {
                 GUILayout.Label(jogador);
             }
         }
         GUILayout.EndArea();
         GUILayout.BeginArea(new Rect((Screen.width / 2), 5, (Screen.width / 2) - 5, Screen.height - 10), "", "box");
         {
             if(GUILayout.Button("Spawn"))
             {
                 Spawn(0, 0);
             }
         }
         GUILayout.EndArea();
     }
 
     [RPC]
     void addPlayer(string name)
     {
         Jogadores.Add(name);
         networkView.name = name;
     }
 }
 

ERROR IndexOutOfRangeException: Array index is out of range. fn_NetConfig.Spawn (Int32 mapa, Int32 jogador) (at Assets/ProjetoDefinitivo/Scripts/NetWork/fn_NetConfig.cs:37)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Aug 03, 2014 at 12:30 AM

If the error message lines up with the code above it looks like this is causing your error:

 Characters[jogador]

Since I only see one call to Spawn (line 109), and it passes 0 for jogador, I'm guessing that the Characters array does not have anything assigned. Typically with public variables, the array should be assigned through drag and drop in the Inspector.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image adriano back · Aug 03, 2014 at 07:57 AM 0
Share

yes not have errors I not have placed the script in character

thanks man

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Array index is out of Range!? 1 Answer

Wierd Animation Bug 0 Answers

C# - IndexOutOfRangeException - Array index is out of range 2 Answers

IndexOutOfRangeException 1 Answer

Random object, Array index out of range 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges