NullReferenceException Problem (u.u)

hi, well, after of all the problem`s with my script of IA, finnaly can fix all the problems with him. now, when start the game, appers this:

if press in the message, unity go to the rango de vision script here:

here is the 3 scrtipts… again:

#pragma strict

function Start () {

}

function Update () {


}

function OnTriggerEnter (other : Collider){

if (other.gameObject.tag == "Player" ){

other.gameObject.GetComponent(EstadoScript).estado = 1;

}

}



function OnTriggerExit (other : Collider){

if (other.gameObject.tag == "Player" ){

other.gameObject.GetComponent(EstadoScript).estado = 0;


}

}
#pragma strict

function Start () {

       
}

function Update () {
   
}

function OnTriggerEnter (other : Collider){

if (other.gameObject.tag == "Player" ){

other.gameObject.GetComponent(EstadoScript).estado = 2;



}
}

function OnTriggerExit (other : Collider){

if (other.gameObject.tag == "Player" ){

other.gameObject.GetComponent(EstadoScript).estado = 1;


}

}
#pragma strict
var estado : int = 0; //estado de inteligencia artificial en el que se encuentra
var vida : float = 100;

var muerto : boolean = false;

var nada : AnimationClip;
var corre : AnimationClip;
var ataca1 : AnimationClip;
var muere : AnimationClip;

var player : Transform;

function Start () {
   
}

function Update () {

if (estado == 0){

GetComponent.<Animation>().Play (nada.name);

}

if (estado == 1){

GetComponent.<Animation>().Play (corre.name);
transform.LookAt(player);
transform.Translate (Vector3 (0,0,1)*Time.deltaTime);

}

if (estado == 2){

GetComponent.<Animation>().Play (ataca1.name);

}

if (estado == 3){

GetComponent.<Animation>().Play (muere.name);

Destroy (this.gameObject, 2);
}

if (vida <= 0){
   
muerto = true;

}

if (muerto == true){

estado = 3;

vida = 0;

}

  }

function OnTriggerEnter (other : Collider ){

if (other.gameObject.tag == "ManodelPlayer"){

vida -= 20;
}



}

and here is the gameobjects… rango de vision and rango de ataque:

i wait what us can do help me u.u

thank you bros u.u

It’s a null error and it tells you what lines in what scripts are null. So figuring it out is looking at the script and seeing what could be null. The line 16 error makes me wonder if your player has the EstadoScript attached to them. I’d check that first.

The other script points to line 41 of a script, but no clue which script it is or what line it is since only the third script goes to 41 and it has nothing on line 41. But, you just need to look at BotControlScript on line 41 and see what could be null on that line.

That should help some hopefully.

the EstadoScript is not attached to the player else at enemy, because this script is to the artificial intelligence. now, my question is the next:

this must be attached to the player, or something this? :v i confused

pd: the nullreference of the botscript i dont care, only care the error the script of rango de vision & ataque, because not leat me continue the game, i mean the game is stopped when this pass :v

You are checking

if (other.gameObject.tag == "Player" ){
other.gameObject.GetComponent(EstadoScript).estado = 2;

This says to check if the other target is tagged as Player. If they are tagged as Player, find the EstadoScript on them and set the field estado to 2. If there is no EstadoScript on the player, then you get your null error. So whatever the script is attached to is the gameobject you need to target if that is your intent.

i mean what i do attached this scripts too at the gameObject tagged how: “Player” right? to the error disappears?

If you put a EstadoScript on your player, then the error will go away, but only you know if that is what you mean to do.

no exactly, because that scripts is to the enemies of the game, not to the player… anyway :v

Unfortunately I can’t see your setup. I can just tell you why you are getting the null error. Now you need to figure out how to get the EstadoScript. If it’s on the same object that the script with the trigger is on? If so, you just use gameObject.GetComponent. You don’t target other.

finnaly can fix all the problems bro… the error of NullReferenceException was because in OnTriggerEnter. In the part of

if (other.gameObject.tag == "Player" ){
other.gameObject.GetComponent(EstadoScript).estado = 2;

was the word “other” so the unity says error because not find this definition or this object, since this was a object fictional.

a last question, and with this i complete my quest:

how can, in the ontriggerenter, say to unity, to make a determined action when two specific objects do collision?

example: when the collision of the player do collision with a box collider what stay inside of the enemy

thank you for all bro. to you, and all the person`s what helped me :slight_smile:

I’m sorry, I don’t understand the question.

Are you looking for the collision detection? Unity - Scripting API: Collider.OnCollisionEnter(Collision)

now, i want what inside of the script, recognize two specifics collisions. Why want this? because inside of the enemy there are one sphere Collider, and a box collider, so… for what not collision the sphere and the box at same time, i want specify which object will collide with the player :slight_smile: