x


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.

more ▼

asked Oct 18 '11 at 11:44 AM

bergarox gravatar image

bergarox
1 4 5 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Anyone to help plz?

more ▼

answered Oct 21 '11 at 01:01 AM

bergarox gravatar image

bergarox
1 4 5 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1288
x1071
x983
x672
x599

asked: Oct 18 '11 at 11:44 AM

Seen: 1210 times

Last Updated: Oct 21 '11 at 01:01 AM