- Home /
Possibility of adding More than One Projectile
Well I have a turret script here but I was wondering if I can possibly have the script shoot more than one projectile randomly. Any help, points in direction or answers are greatly appreciated. Thanks for the looking, Sincerely Cobalt60
pragma strict
var myProjectile : GameObject; var reloadTime : float = 1f; var turnSpeed : float = 5f; var firePauseTime : float = .25f; var errorAmount : float = .001; var myTarget : Transform; var muzzlePositions : Transform[]; var pivot_Tilt : Transform; var pivot_Pan : Transform; var aim_Pan : Transform; var aim_Tilt : Transform;
private var nextFireTime : float;
function Start () {
}
function Update () { if(myTarget) { aim_Pan.LookAt(myTarget); aim_Pan.eulerAngles = Vector3(0, aim_Pan.eulerAngles.y,0); aim_Tilt.LookAt(myTarget);
pivot_Pan.rotation = Quaternion.Lerp(pivot_Pan.rotation, aim_Pan.rotation,Time.deltaTime*turnSpeed);
pivot_Tilt.rotation = Quaternion.Lerp(pivot_Tilt.rotation, aim_Tilt.rotation,Time.deltaTime*turnSpeed);
if(Time.time >= nextFireTime)
{
FireProjectile();
}
} }
function OnTriggerEnter(other : Collider) { if(other.gameObject.tag == "Enemy") { nextFireTime = Time.time+(reloadTime*.5); myTarget = other.gameObject.transform; } }
function OnTriggerExit(other : Collider) { if(other.gameObject.transform == myTarget) { myTarget = null; } }
function FireProjectile()
{
audio.Play();
nextFireTime = Time.time+reloadTime;
var m : int = Random.Range(0,6);
var newMissile = Instantiate(myProjectile, muzzlePositions[m].position, muzzlePositions[m].rotation);
newMissile.GetComponent(Projectile_Missile).myTarget = myTarget;
}
Sorry the question that I asked is not perceptible in the way I want it. What I meant to get at, is that I would like to change the script to be able to shoot different models of projectiles randomly. Right now it can shoot one model. Which say is a blue ball. It would be nice for it to be able to shoot say a blue, orange, green, and red ball. Hope this clears it up a bit.
Answer by Benproductions1 · Aug 04, 2012 at 11:04 AM
easy :D
var Missiles:Transform[];
//Add that to the start and make myProjectile a private variable and a Transform var
//and in unity add the prefabs to the list
function FireProjectile() {
//Add this to your fire function
myProjectile = Missiles[Random.Range(0, Missiles.length-1)];
}
Hope this helps :)
Benproductions1
Your answer
Follow this Question
Related Questions
Tank Turret move on XAxis by Mouse XAxis 1 Answer
enemy AI script 3 Answers
is it possible to use the enter and exit script to enter a turret? 0 Answers
Trouble with selective projectile script 0 Answers
Easy Animation/Modeling question 2 Answers