- Home /
Question by
Wololo Plays · Jun 06, 2014 at 10:59 PM ·
errorobjectnooblifebar
Error : Object reference not set to an instance of an object body.Update
My unity is with the following problem:
NullReferenceException: Object reference not set to an instance of an object body.Update() (at Standard Assets/Assets/Menu/corpo.js: 20)
Tags and some elements as in Portuguese of Brazil
#pragma strict
var Vida: float;
var TVida : TextMesh;
var TempoQueda: float;
function Start () {
Vida = 100;
TempoQueda=-1;
}
function Update () {
if (TempoQueda>=0)
{
TempoQueda += Time.deltaTime;
}
TVida = transform.GetComponentInChildren(TextMesh);
TVida.text = "Vida: "+Vida;
}
var testeInpacto : Vector3;
function OnCollisionEnter(collision: Collision)
{
testeInpacto = collision.impactForceSum;
if (testeInpacto.y<10)
{
if (collision.transform.tag!="agua")
{
if (TempoQueda>1)
{
Vida = Vida - (100 * (TempoQueda/3));
}
}
}
TempoQueda=-1;
}
function OnCollisionExit(collisioninfo : Collision) {
TempoQueda = 0 ;
}
Comment
Answer by Bilelmnasser · Jun 06, 2014 at 11:12 PM
NullReferenceException mean : you are trying to access a NULL Object (var TVida : TextMesh;), you cannot access that object because he is null :) you need to instantiate the TVida object or assigned to not null value :)
What do you mean? I'm kind of new in unity ... not even a month and took this scipt on a video
TVida = transform.GetComponentInChildren(Text$$anonymous$$esh); this line don't work my guess
and make sure your object has a textmesh component :)