SchultzGames
Para tirar dúvidas, crie um tópico especifico na área "Dúvidas em Geral" e aguarde ser respondido. Evite comentar em tópicos não relacionados a sua dúvida :D
TÓPICOS RECENTES:
Tópico:
Postado em:
Postado por:
Jogo Mobile - Ultimate Flight Simulator - Real World SDK
Unity - FPS e CPU ???
Usar microfone na Unity
Jogo ficando escuro quando faço a Build pela cena menu
Dúvida sobre movimentação do personagem
[RESOLVIDO] ACESSAR SCRIPT DE OUTRO GAMEOBJECT
Para eu ter shader em meu projeto eu tenho que usar o hdrp ou o 3d padrao?
Rotate Camera Mobile
Sou modelador 3d (!!! Arquitetonico!!!) Disponivel !!!!!!
Preciso de alguém que saiba programação e Raycast
Servidor/cliente usando sockets
Assets carregados com addressables causando erro na versão "buildada"
Jogo multiplayer com salas - não vai para o lobby
Texto - Não escreve no 'play'. Clica mais não digita.
Error Unity Vulkan - Out of memory! (allocating memory for image)
Câmera Não esta renderizando na segunda janela.
Movimento da Câmera No Android
[RESOLVIDO] - Unity não está mais funcionando o "Build and Run"
Precisa de modelador com ou sem experiência
Duvida com "mesclagem" de animação
[TUTORIAL] Como fazer uma gota de água na Unity
Missoes Aparecerem aleatoriamente do nada
Dúvida pafra IOS
botoes não esta funcionando corretamente nem a fisica?
Duvida com NavMeshAgent
COMO AUMENTAR E DIMINUÍ A SENSIBILIDADE DO TOQUE POR CÓDICO (MOBILE)
A Licença da Unity só funciona se eu tiver Internet
Problema com OnTriggerEnter
Transparência ao colidir
bool para evitar de salvar frames repetido
Unity - Transições no AnimatorController rodando errado
problemas com "wall Jump" , atribuir força ao eixo X
Meu Jogo ja Esta Pronto! EXPERIMENTEM!!
JOSTICK NAO SE MOVE
botoes para mobile
ERRO NO SCRIPT FOME E SEDE ETC
CORTAR ARVORES E DROPAR
Configurar sistema
Unity - Sugestões da Loja
Standard Assets para UNITY 5 em ".unitypackage"
Problema com o Shader
[TUTORIAL] Sistema Simples de Falas
Velocímetro Bugado
Como faço para alinhar uma textura na posição absoluta do mundo no shader
Sobre o Tutorial de Cortar Arvores
Erro Mov Player
[TUTORIAL] VELOCIMETRO DE PONTEIRO
[TUTORIAL] Ligar/Desligar luz por Interruptor
Sistema de lampadas
Conversor de movimento do Unity para o MMD [Ajuda]
Script de configurações não esta funcionando corretamente
CAMERA BUGANDO NA TRANSIÇÃO DE CENA
Volante girando errado [AJUDA]
Novo Asset Sistema de Portas e Chaves
ERRO NAS RODAS DO CARRO
[TUTORIAL] Sistema de câmera em primeira pessoa SIMPLES
AJUDA PARA UM SISTEMA DE CHECKPOINT
Jogo offline com Loja?
Unity -TextMeshProUGUI- 1 das coisas q estão deixando a scene lenta p abrir
Detectar quando o animation curve chega no final
Problema com compilação para Android na Unity 2019.4.35
Aplicativo para IOS
Árvores feitas na Unity
RECRUTAMENTO WAR CORE FPS
[RESOLVIDO] Unity - Scrollbar não funciona
[TUTORIAL] AI que cria scripts para você, inclusive scripts para Unity !!!!
[RESOLVIDO] Animando Image na Unity não funciona
Hospedar um jogo multiplay na itch.io
Script para detetectar o movimento do player
Alguém ajuda com um erro por favor? PSDImporter.cs
[RESOLVIDO] - Unity - Rotação da Câmera - Mathf.Clamp não funciona
Alterar textura .unity3d
Comportamento do movimento do inimigo. Sair do caminho e Fugir
Procuro uma equipe
Ajuda Com Sala de Jogo Multiplayer
COMO FAZER A PORTA ABRIR SÓ EMPURRANDO ELA COM O PLAYER?
Visual Studio - Vend os Scripts na Aba "Modo de Exibição de Classe" soltos
app fica fechendo após mobile notification
[RESOLVIDO] Controlar dois player dentro de um jogo multiplay usando mirror
Unity - O Jogo fecha quando vai abrir a Scene
[TUTORIAL] Mudando material
Procuro programador Unity para jogo 2D
AJUDA REALISTIC CAR CONTROLLER
Chama para isqueiro
[RESOLVIDO] Ajuda para destruir objeto
Unity - Sistema de Giro da Tela - Ajuda pfv!
Unity - Touch na Tela do Celular
Dawn Of Hell - Horror Game BR (2022-2023)
Unity - Jogo online ou offline?
ANIMAÇÃO INIMIGO ESTÁ INDO PRA TUDO QUANTO É LADO
[RESOLVIDO] Erro de Script no Android
Bundle Assets, Resources, e Addressables
Jogo online (qual a melhor opção?)
Dúvida sobre como criar o inimigo IA!
Unity dando pause no jogo a cada 4 segundos
bom dia amigos eu sou meio lego nos scripts será que alguem pode me ajudar
JOGO "CHALLENGE" FINALIZADO E DISPONÍVEL PARA BAIXAR.
error CS0246
[TUTORIAL]Como Chamar Um Método Usando Uma String como Parametro
Ontem à(s) 2:41 pm
Ter maio 30, 2023 7:28 pm
Ter maio 30, 2023 6:04 am
Seg maio 29, 2023 7:53 pm
Sáb maio 27, 2023 3:11 pm
Sex maio 26, 2023 4:59 pm
Sex maio 26, 2023 11:27 am
Qui maio 25, 2023 10:33 am
Sáb maio 20, 2023 12:25 pm
Ter maio 16, 2023 5:43 pm
Ter maio 16, 2023 5:42 pm
Ter maio 09, 2023 7:42 pm
Seg maio 08, 2023 7:13 am
Seg maio 08, 2023 6:38 am
Seg maio 08, 2023 1:49 am
Sáb maio 06, 2023 11:44 pm
Sáb maio 06, 2023 6:42 pm
Sáb maio 06, 2023 1:35 am
Qua maio 03, 2023 12:32 pm
Seg maio 01, 2023 8:51 pm
Seg maio 01, 2023 12:29 pm
Dom Abr 30, 2023 8:49 pm
Dom Abr 30, 2023 5:06 pm
Sáb Abr 29, 2023 4:05 pm
Qui Abr 27, 2023 4:39 pm
Qui Abr 27, 2023 12:40 am
Ter Abr 25, 2023 5:33 pm
Ter Abr 25, 2023 10:23 am
Dom Abr 23, 2023 12:11 am
Sáb Abr 22, 2023 4:27 am
Sex Abr 21, 2023 11:38 pm
Sex Abr 21, 2023 10:21 pm
Qui Abr 20, 2023 4:57 pm
Qui Abr 20, 2023 12:28 pm
Qua Abr 19, 2023 3:03 pm
Qua Abr 19, 2023 1:52 pm
Qua Abr 19, 2023 11:59 am
Qua Abr 19, 2023 11:54 am
Sáb Abr 15, 2023 8:13 pm
Sex Abr 14, 2023 7:43 am
Qui Abr 13, 2023 4:36 pm
Qui Abr 13, 2023 4:36 pm
Qua Abr 12, 2023 6:05 pm
Ter Abr 11, 2023 6:22 pm
Seg Abr 10, 2023 7:33 pm
Seg Abr 10, 2023 3:25 pm
Dom Abr 09, 2023 8:53 pm
Dom Abr 09, 2023 7:26 pm
Dom Abr 09, 2023 5:59 pm
Dom Abr 09, 2023 12:06 am
Sex Abr 07, 2023 7:24 pm
Qui Abr 06, 2023 6:45 am
Qua Abr 05, 2023 9:24 am
Ter Abr 04, 2023 4:55 pm
Ter Abr 04, 2023 1:00 pm
Dom Abr 02, 2023 11:52 pm
Sex Mar 31, 2023 12:50 pm
Sex Mar 31, 2023 11:03 am
Sex Mar 31, 2023 10:05 am
Qua Mar 29, 2023 7:48 pm
Ter Mar 28, 2023 10:50 pm
Ter Mar 28, 2023 9:19 am
Seg Mar 27, 2023 10:16 am
Dom Mar 26, 2023 7:39 pm
Qui Mar 23, 2023 4:52 pm
Ter Mar 21, 2023 11:20 pm
Ter Mar 21, 2023 8:52 pm
Sáb Mar 18, 2023 8:41 pm
Sex Mar 17, 2023 3:12 pm
Sex Mar 17, 2023 1:24 pm
Seg Mar 13, 2023 10:45 pm
Seg Mar 13, 2023 9:48 pm
Seg Mar 13, 2023 8:24 pm
Seg Mar 13, 2023 7:17 pm
Dom Mar 12, 2023 10:27 pm
Dom Mar 12, 2023 7:22 pm
Sex Mar 10, 2023 8:26 pm
Sex Mar 10, 2023 8:00 pm
Qui Mar 09, 2023 9:05 am
Ter Mar 07, 2023 2:27 pm
Sex Mar 03, 2023 6:47 pm
Sex Mar 03, 2023 12:01 am
Qui Mar 02, 2023 4:00 pm
Qui Mar 02, 2023 1:35 pm
Qua Mar 01, 2023 5:47 pm
Qua Mar 01, 2023 2:11 am
Seg Fev 27, 2023 11:08 pm
Seg Fev 27, 2023 7:19 pm
Dom Fev 26, 2023 11:49 pm
Dom Fev 26, 2023 8:29 pm
Dom Fev 26, 2023 7:47 pm
Dom Fev 26, 2023 7:46 pm
Dom Fev 26, 2023 6:08 pm
Sáb Fev 25, 2023 8:16 pm
Seg Fev 13, 2023 7:02 pm
Seg Fev 13, 2023 2:44 am
Dom Fev 12, 2023 9:57 pm
Dom Fev 12, 2023 2:19 pm
Sáb Fev 11, 2023 1:01 pm



































































































erro IndexOutOfRangeException: Index was outside the bounds of the array.

2 participantes

Ir para baixo

DÚVIDA erro IndexOutOfRangeException: Index was outside the bounds of the array.

Mensagem por edu63 Dom Set 26, 2021 4:43 pm

ta dando esse erro e ja teitei algumas coisas mas n resouvel so pioro então se vcs poderem me ajudar pois n sei muito sobre scripts 

script que uso
Código:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WeaponManager : MonoBehaviour
{
    private GameObject[] weaponsInUse = new GameObject[2];
    public GameObject[] weaponsInGame;
    public Rigidbody[] worldModels;

    public RaycastHit hit;
    private float dis = 3.0f;
    public LayerMask layerMaskWeapon;
    public LayerMask layerMaskAmmo;

    public Transform dropPosition;

    private float switchWeaponTime = 0.25f;
    public bool canSwitch = true;
   private bool equipped = false;
    [HideInInspector] public bool showWepGui = false;
    [HideInInspector] public bool showAmmoGui = false;
    [HideInInspector] public int weaponToSelect;
    [HideInInspector] public int setElement;
    [HideInInspector] public int weaponToDrop;
   [HideInInspector] public float crosshairSize;

    public AudioClip pickupSound;
    public AudioSource aSource;
    public HealthScript hs;
    private string textFromPickupScript = "";
    private string notes = "";
    private string note = "Press key <color=#88FF6AFF> << E >> </color> to pick up Ammo";
    private string wrongType = "Select appropriate weapon to pick up";
    public int selectWepSlot1 = 0;
    public int selectWepSlot2 = 0;
   Text noteUI;
   
    void Start()
    {
      noteUI = CanvasManager.instance.note;
      CanvasManager.instance.SetWeapon(this);
      
        for (int h = 0; h < worldModels.Length; h++)
        {
            weaponsInGame[h].SetActive(false);
        }

        weaponsInUse[0] = weaponsInGame[selectWepSlot1];
        weaponsInUse[1] = weaponsInGame[selectWepSlot2];

        weaponToSelect = 0;
        StartCoroutine(DeselectWeapon());
    }
   
    void Update() {
   
        if (Cursor.lockState == CursorLockMode.None) return;

        if (Input.GetKeyDown("1") && weaponsInUse.Length >= 1 && canSwitch && weaponToSelect != 0)
        {
            StartCoroutine(DeselectWeapon());
            weaponToSelect = 0;
        }
        else if (Input.GetKeyDown("2") && weaponsInUse.Length >= 2 && canSwitch && weaponToSelect != 1)
        {
            StartCoroutine(DeselectWeapon());
            weaponToSelect = 1;
        }

        if (Input.GetAxis("Mouse ScrollWheel") > 0 && canSwitch)
        {
            weaponToSelect++;
            if (weaponToSelect > (weaponsInUse.Length - 1))
            {
                weaponToSelect = 0;
            }
            StartCoroutine(DeselectWeapon());
        }

        if (Input.GetAxis("Mouse ScrollWheel") < 0 && canSwitch)
        {
            weaponToSelect--;
            if (weaponToSelect < 0)
            {
                weaponToSelect = weaponsInUse.Length - 1;
            }
            StartCoroutine(DeselectWeapon());
        }

        Vector3 pos = transform.parent.position;
        Vector3 dir = transform.TransformDirection(Vector3.forward);
        if (Physics.Raycast(pos, dir, out hit, dis, layerMaskWeapon))
        {
            WeaponIndex pre = hit.transform.GetComponent<WeaponIndex>();
            setElement = pre.setWeapon;
         
         if(!showWepGui)
         {         
            if (weaponsInUse[0] != weaponsInGame[setElement] && weaponsInUse[1] != weaponsInGame[setElement])
            {
               equipped = false;
               noteUI.text = "Press key <color=#88FF6AFF> << E >> </color> to pickup weapon";
            }
            else
            {
               equipped = true;
               noteUI.text = "Weapon is already equipped";
            }
            showWepGui = true;
         }
         
            if (canSwitch && !equipped)
            {
                if (Input.GetKeyDown("e"))
                {
                    DropWeapon(weaponToDrop);
                    StartCoroutine(DeselectWeapon());
                    weaponsInUse[weaponToSelect] = weaponsInGame[setElement];
                    Destroy(hit.transform.gameObject);
                }
            }
        }
        else
        {
         if(showWepGui)
         {   
            noteUI.text = "";
            showWepGui = false;
         }
        }

        if (Physics.Raycast(pos, dir, out hit, dis, layerMaskAmmo))
        {
            if (hit.transform.CompareTag("Ammo"))
            {
                Pickup pickupGO = hit.transform.GetComponent<Pickup>();

                //bullets/magazines
                if (pickupGO.pickupType == PickupType.Magazines)
                {
                    WeaponScriptNEW mags = weaponsInUse[weaponToSelect].transform.GetComponent<WeaponScriptNEW>();
                    if (mags == null)
                    {
                        textFromPickupScript = "";
                        return;
                    }
                    if (mags.firstMode != fireMode.launcher)
                    {
                        notes = "";
                        textFromPickupScript = note;
                        if (Input.GetKeyDown("e"))
                        {
                            if (mags.ammoMode == Ammo.Magazines)
                                mags.magazines += pickupGO.amount;
                            else
                                mags.magazines += pickupGO.amount * mags.bulletsPerMag;

                     CanvasManager.instance.UpdateMags(mags.magazines);
                     aSource.PlayOneShot(pickupSound, 0.3f);
                            Destroy(hit.transform.gameObject);
                        }
                    }
                    else
                    {
                        textFromPickupScript = pickupGO.AmmoInfo;
                        notes = wrongType;
                    }
                }

                //projectiles/rockets
                if (pickupGO.pickupType == PickupType.Projectiles)
                {
                    WeaponScriptNEW projectile = weaponsInUse[weaponToSelect].transform.GetComponent<WeaponScriptNEW>();
                    if (projectile == null)
                    {
                        textFromPickupScript = "";
                        return;
                    }
                    if (projectile.secondMode == fireMode.launcher || projectile.firstMode == fireMode.launcher)
                    {
                        notes = "";
                        textFromPickupScript = note;
                        if (Input.GetKeyDown("e"))
                        {
                            projectile.projectiles += pickupGO.amount;
                     CanvasManager.instance.UpdateProjectileUI(projectile.projectiles);
                            aSource.PlayOneShot(pickupSound, 0.3f);
                            Destroy(hit.transform.gameObject);
                        }
                    }
                    else
                    {
                        textFromPickupScript = pickupGO.AmmoInfo;
                        notes = wrongType;
                    }
                }

                //health
                if (pickupGO.pickupType == PickupType.Health)
                {
                    textFromPickupScript = pickupGO.AmmoInfo;
                    notes = "";
                    if (Input.GetKeyDown("e"))
                    {
                        hs.Medic(pickupGO.amount);
                        aSource.PlayOneShot(pickupSound, 0.3f);
                        Destroy(hit.transform.gameObject);
                    }
                }
            }
         
         if(!showAmmoGui)
         {
            noteUI.text = notes + "\n" + textFromPickupScript;
            showAmmoGui = true;
         }   
        }
        else
        {
         if(showAmmoGui)
         {   
            noteUI.text = "";
            showAmmoGui = false;
         }
        }
    }

    IEnumerator DeselectWeapon()
    {
        canSwitch = false;

        for (int i = 0; i < weaponsInUse.Length; i++)
        {
         if(weaponsInUse[i].GetComponent<WeaponScriptNEW>() != null)
            weaponsInUse[i].GetComponent<WeaponScriptNEW>().Deselect();
            weaponsInUse[i].gameObject.SetActive(false);
        }

        yield return new WaitForSeconds(switchWeaponTime);
        SelectWeapon(weaponToSelect);
        yield return new WaitForSeconds(switchWeaponTime);
        canSwitch = true;
    }
   
    void SelectWeapon(int i)
    {
        weaponsInUse[i].gameObject.SetActive(true);
        weaponsInUse[i].SendMessage("DrawWeapon", SendMessageOptions.DontRequireReceiver);
        WeaponIndex temp = weaponsInUse[i].transform.GetComponent<WeaponIndex>();
        weaponToDrop = temp.setWeapon;
    }

    void DropWeapon(int index)
    {
        if (index == 0) return;

        for (int i = 0; i < worldModels.Length; i++)
        {
            if (i == index)
            {
                Rigidbody drop = Instantiate(worldModels[i], dropPosition.transform.position, dropPosition.transform.rotation) as Rigidbody;
                drop.AddRelativeForce(0, 250, Random.Range(100, 200));
                drop.AddTorque(-transform.up * 40);
            }
        }
    }

    public void EnterWater()
    {
        canSwitch = false;
        for (int i = 0; i < weaponsInUse.Length; i++)
        {
         if(weaponsInUse[i].GetComponent<WeaponScriptNEW>() != null)
            weaponsInUse[i].GetComponent<WeaponScriptNEW>().Deselect();
            weaponsInUse[i].gameObject.SetActive(false);
        }
    }

    public void ExitWater()
    {
        canSwitch = true;
        SelectWeapon(weaponToSelect);
    }
}

edu63
Iniciante
Iniciante

PONTOS : 796
REPUTAÇÃO : 1
Respeito as regras : erro IndexOutOfRangeException: Index was outside the bounds of the array. WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: erro IndexOutOfRangeException: Index was outside the bounds of the array.

Mensagem por TIKO Dom Set 26, 2021 4:50 pm

https://forum.unity.com/threads/indexoutofrangeexception-index-was-outside-the-bounds-of-the-array.577657/

https://www.codeproject.com/Questions/5251668/Indexoutofrangeexception-index-was-outside-the-bou

https://stackoverflow.com/questions/60287644/very-simple-code-unity-3d-indexoutofrangeexception-index-was-outside-the-bo
TIKO
TIKO
Avançado
Avançado

Masculino PONTOS : 1252
REPUTAÇÃO : 29
Idade : 15
Áreas de atuação : Modelagem 3D (Básico), Programação (Mais básico ainda), Unity 3D, C#
Respeito as regras : erro IndexOutOfRangeException: Index was outside the bounds of the array. WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: erro IndexOutOfRangeException: Index was outside the bounds of the array.

Mensagem por TIKO Dom Set 26, 2021 4:51 pm

TIKO escreveu:https://forum.unity.com/threads/indexoutofrangeexception-index-was-outside-the-bounds-of-the-array.577657/

https://www.codeproject.com/Questions/5251668/Indexoutofrangeexception-index-was-outside-the-bou

https://stackoverflow.com/questions/60287644/very-simple-code-unity-3d-indexoutofrangeexception-index-was-outside-the-bo

Vê se ajuda
TIKO
TIKO
Avançado
Avançado

Masculino PONTOS : 1252
REPUTAÇÃO : 29
Idade : 15
Áreas de atuação : Modelagem 3D (Básico), Programação (Mais básico ainda), Unity 3D, C#
Respeito as regras : erro IndexOutOfRangeException: Index was outside the bounds of the array. WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: erro IndexOutOfRangeException: Index was outside the bounds of the array.

Mensagem por edu63 Dom Set 26, 2021 5:09 pm

TIKO escreveu:
TIKO escreveu:https://forum.unity.com/threads/indexoutofrangeexception-index-was-outside-the-bounds-of-the-array.577657/

https://www.codeproject.com/Questions/5251668/Indexoutofrangeexception-index-was-outside-the-bou

https://stackoverflow.com/questions/60287644/very-simple-code-unity-3d-indexoutofrangeexception-index-was-outside-the-bo

Vê se ajuda
vlw mano ajudo consegui resolver

edu63
Iniciante
Iniciante

PONTOS : 796
REPUTAÇÃO : 1
Respeito as regras : erro IndexOutOfRangeException: Index was outside the bounds of the array. WvDYdlf

Ir para o topo Ir para baixo

DÚVIDA Re: erro IndexOutOfRangeException: Index was outside the bounds of the array.

Mensagem por TIKO Dom Set 26, 2021 5:19 pm

Smile Curti isso
TIKO
TIKO
Avançado
Avançado

Masculino PONTOS : 1252
REPUTAÇÃO : 29
Idade : 15
Áreas de atuação : Modelagem 3D (Básico), Programação (Mais básico ainda), Unity 3D, C#
Respeito as regras : erro IndexOutOfRangeException: Index was outside the bounds of the array. WvDYdlf

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos