栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

c#中关于Object reference not set to an instance of an object物体未实例化的一个问题

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c#中关于Object reference not set to an instance of an object物体未实例化的一个问题

浅浅记录一下在写c#脚本过程中遇到的一个实例化问题

在编写中,本想着使用Vector3类创建一个三维矩形数组来储存地图中的一些位置,代码如下

public static int R =3, C=5, R1=3, C1=3;
public static Vector3[ , , ] Points;

for (int y = 9 - C1; y > 9 - m * R - C1;y = y - m)
        {
            for (int x = -17 + R1; x < -17 + n * C + R1; x= x + n )
            {
               for(int i = 0;i < R; i++)
                {
                    for(int j = 0; i < C; j++)
                    {
                        Points[i, j, 0] = new Vector3 (x, y, 0);
                        Points[i, j, 1] = new Vector3 (x+1, y, 0);
                        Points[i, j, 2] = new Vector3 (x, y-1, 0);
                        Points[i, j, 3] = new Vector3 (x+1, y-1, 0);
                    }
                }
            }
        }

但是发现我只声明了Vector3数组,并没有实例化,导致脚本在unity中运行时出错

 解决这个问题的关键就是要在数组声明的同时进行实例化

public static int R =3, C=5, R1=3, C1=3;

public static Vector3[ , , ] turnPoints=new Vector3[R, C, 4];

然后就不会报错了

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/906610.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号