- Home /
2d enemy prefab (enemy movement and instantiate)
Hi guys, i believe that this is very simple.
I need to make a 2d enemy prefab, that go for example X positions to left, return to original position and go more x positions to right, changing rotation (always looking to foward).
Well, a simple enemy that stay walking for left and right always on same position. My confused script is working, but when pass some minutes the enemy is changing the original position.
Another thing is, the enemy when is dead he will be deleted, and random instantiate a prefab (LIXO on script), i need for example 20% chance to instantiate LIXO, 40% LIXO2 and 40% LIXO3. I dont know if it is simple.
I made a script:
var aberta=0;
var delta = 0.0;
var volta : boolean = false;
var marcador : float = 0;
var marcadorGIRO : float = 0;
var Lixo : GameObject;
var Lixo2 : GameObject;
var Lixo3 : GameObject;
function Update ()
{
marcador += Time.deltaTime;
marcador2 = marcador +1;
transform.position.x = transform.position.x + delta;
if(aberta == 0){
if (marcadorGIRO == 1) {
transform.Rotate(0,180,0);
marcadorGIRO = 0;
}
delta = 0.01 ;
if (marcador >= 1)
{
aberta = 1;
marcadorGIRO =1;
}
if(Screen.fullScreen){
delta = 0.04;
}
}
if(aberta == 1){
if (marcadorGIRO == 1) {
transform.Rotate(0,180,0);
marcadorGIRO = 0;
}
delta = -0.01 ;
if (marcador >= 2)
{
aberta = 0;
marcadorGIRO =1;
marcador = 0;
}
if(Screen.fullScreen){
delta = -0.04;
}
}
}
function OnTriggerEnter (hit:Collider)
{
if (hit.gameObject.tag == "bala")
{
animation.CrossFade ("abelhaMorrendo");
Instantiate(Random.Range(Lixo,Lixo2,Lixo3));
Destroy(gameObject, 0.6);
}
}
Anyone can help??? Really thanks and sorry for my bad english.
I formatted your question for you so others can actually understand what your code is meant to do. You may care to do this in the future. No-one is going to take time to figure out the code when it's just pasted into your question with no attempt to make is presentable.
hum... Sorry i am new here and new with program$$anonymous$$g scripts too.
Thanks for that and the advice, i appreciate.