unity中给自定义类中的属性赋值,报错“Object reference not set to an instance of an object”

unity中给自定义类中的属性赋值,报错“Object reference not set to an instance of an object”,第1张

改成这样

using UnityEngine

using System.Collections

public class ChessBoard : MonoBehaviour {

Coordinate[,] chessBoardPos

void Start () {

chessBoardPos = new Coordinate[8,8]

chessBoardPos [1, 1] = new Coordinate ()

chessBoardPos[1,1].x= 1.111f

}

}

你这样相当于

chessboardpos[1,1] = null

chessboardpos[1,1].x = 1.111f

是空的咋赋值都会告诉你

Object reference not set to an instance of an object

当前的方案是:

animator初始设置为 enable = false

用于触发动作的位置 设置 animator = true

给animaiton clip 添加相应的 behaviour ,(在animator 编辑器中) ,脚本中对 exit 函数进行修改,在退出的时候 将enable = false用于关闭animator 使能。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11697551.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存