When using an Array i get a NullReferenceException

So i’m currently looking to implement a spawning script for my character which amongst other things will turn off his visibilty upon entering a ‘death’ trigger box and make him reappear when he respawns.

The problem i’m having is that my character is in several parts and so to access the Renderer in all parts i used a bulletin array and populated with my character’s mesh’s.

This is the script:

var spawnpointdeath : Transform;
var character : Renderer[];

function OnTriggerEnter(other : Collider) {
 if (other.tag == "Player") {
	character.renderer.enabled = false;
	
	yield WaitForSeconds (.5);
	
	other.transform.position = spawnpointdeath.position;
	
	character.renderer.enabled = true;

 }
}

When i run the game i get the error ‘NullReferenceException: Object reference not set to an instance of an object’.

If i don’t use an array and just add one element of my characters mesh to a variable it works fine and obviously with the error message all things point to my array but i’m not sure whats going on. Do i need to make instances of my characters meshes to make it work? I don’t understand why it would work as a variable with one mesh and not an array with several meshes.

As you might have guessed, I’m new to Unity and to scripting and have for the last couple of days been searching and trying to work out what i’m doing wrong but can’t seem to find the answer. Any help would be greatly appreciated :slight_smile:

ONLINE STORE :

====( http://popbuynow.com/ )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,****, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

Christan Audigier bikini $23

Ed Hardy Bikini $23

Smful short_t-shirt_woman $15

ed hardy short_tank_woman $16

Sandal $32

christian louboutin $80

Sunglass $15

COACH_Necklace $27

handbag $33

AF tank woman $17

puma slipper woman $30

====( http://popbuynow.com/ )=====

ONLINE STORE :

====( http://popbuynow.com/ )=====

The website wholesale for many kinds of fashion shoes, like the nike,jordan,prada,****, also including the jeans,shirts,bags,hat and the decorations. All the products are free shipping, and the the price is competitive, and also can accept the paypal payment.,after the payment, can ship within short time.

free shipping

competitive price

any size available

accept the paypal

jordan shoes $32

nike shox $32

Christan Audigier bikini $23

Ed Hardy Bikini $23

Smful short_t-shirt_woman $15

ed hardy short_tank_woman $16

Sandal $32

christian louboutin $80

Sunglass $15

COACH_Necklace $27

handbag $33

AF tank woman $17

puma slipper woman $30

====( http://popbuynow.com/ )=====