Tuesday, 15 January 2013

unityscript - unity3d how can i delete enemy :S and not the animator -



unityscript - unity3d how can i delete enemy :S and not the animator -

how delete enemy on enemyprefab not enemanim animator?

#pragma strict var enemy : gameobject; var speed : float = 1.0; var enemanim : animator; function start() { this.transform.position.x = 8.325; this.transform.position.y = -1.3; enemanim = this.getcomponent(animator); enemanim.setfloat("isdead", 0); } function oncollisionenter2d(coll: collision2d) { if (coll.gameobject.comparetag("distroy")) { destroy(this.gameobject); } } function enemstruck() { enemanim.setfloat("isdead", 1); } function fixedupdate() { this.transform.translate(vector3(input.getaxis("horizontal") * speed * time.deltatime, 0, 0)); this.rigidbody2d.velocity = vector2(-5, 0); }

this enemy prefab code instantiating in main

these 2 var:

var enemytrans : transform; var enemy : gameobject; function start () { while (true) { yield waitforseconds (random.range(3, 0)); enemy = instantiate(enemytrans).gameobject; }

i think cannot delete gameobject , save 1 of components. every component needs attached gameobject , cannot move them other gameobjects either.

what can remove other components gameobject , same result. can remove component next script:

destroy(gameobject.getcomponent(yourcomponent));

unity3d unityscript unity3d-2dtools

No comments:

Post a Comment