x


Fire when plane enters area

What I'm wanting to make is a script so that when my airplane enters a box that I have place around my tank the tank then starts to fire on the plane. The plane is tagged player the tank does not move. I'm not sure is the box needs to be chileded to the tank, or not. I know the code will be a function with OnTriggerEnter just not sure how to make it start. The bullet will for now just be a ball.

more ▼

asked Dec 19 '11 at 12:14 AM

Davidflynn gravatar image

Davidflynn
61 22 49 55

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

1 answer: sort voted first

I'd just use Vector3.Distance instead...

@HideInInspector
var player : GameObject ;
@HideInInspector
var _myTrans : Transform ;
var inRange : float = 100 ;
@HideInInspector
var distance : float ;
 
function Start(){
player = GameObject.FindWithTag("Player") ;
var _myTrans = transform ;
}
 
function Update(){
distance = Vector3.Distance(player.transform.position, _myTrans.position) ;
   if(distance < inRange){
      TankAttack() ;
   }
}
 
function TankAttack(){
   //whatever it is you have for the tank to shoot
}

...somethin like that anyway. This script would attach to your tank object.

more ▼

answered Dec 19 '11 at 02:11 AM

Lo0NuhtiK gravatar image

Lo0NuhtiK
3.5k 1 9 39

(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:

x959
x255
x60

asked: Dec 19 '11 at 12:14 AM

Seen: 371 times

Last Updated: Dec 19 '11 at 02:12 AM