- Home /
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.
Answer by Lo0NuhtiK · Dec 19, 2011 at 02:11 AM
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.
Your answer
Follow this Question
Related Questions
Tank AI script that calculates distance of targets and firing angle 1 Answer
Lock rotation of object 4 Answers
[Solved] NPC kinda sorta slides under player 1 Answer
AI enemy vechicle problem 2 Answers
My AI is flying when I jump 2 Answers