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.
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.