微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我在我的统一代码 (C#) 上得到一个 IndexOutOfRangeExcectation

如何解决我在我的统一代码 (C#) 上得到一个 IndexOutOfRangeExcectation

这是代码,我是初学者,我已经坚持了很长时间,统一控制台说“IndexOutOfRangeException:索引超出了数组的范围。”我需要为 stackoverflow 添加更多文本以便我发布,因此向下滚动代码并忽略以下垃圾邮件文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本文本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehavIoUr
{

    public Animator anim;
    public Rigidbody2D rb;
    public float jumpForce;
    public float playerSpeed;
    public Vector2 jumpHeight;
    private bool isOnGround;
    public float positioinRadius;
    public LayerMask ground;
    public Transform playerPos;



    void Start()
    {
        Collider2D[] colliders = transform.GetComponentsInChildren<Collider2D>();
        for (int i = 0; 1 < colliders.Length; i++)
        {
            for (int k = i + 1; k < colliders.Length; k++)
            {
                Physics2D.IgnoreCollision(colliders[i],colliders[k]);
            }
        }
    }

    void FixedUpdate()
    {
        if (Input.GetAxisRaw("Horizontal") != 0)
        {
            if (Input.GetAxisRaw("Horizontal") > 0)
            {
                anim.Play("Walk");
                rb.AddForce(Vector2.right * playerSpeed * Time.deltaTime);
            }
            else
            {
                anim.Play("WalkBackwards");
                rb.AddForce(Vector2.left * playerSpeed * Time.deltaTime);
            }
        }
        else
        {
            anim.Play("Idle");
        }

        isOnGround = Physics2D.OverlapCircle(playerPos.position,positioinRadius,ground);
        if (isOnGround == true && Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(Vector2.up * jumpForce * Time.deltaTime);
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。