I’m trying to make a Shotlock system similar to the one found in Kingdom Hearts BBS, as seen below:
This Video
Only to be used as a first person perspective.
Now I’ve figured that I can use raycast to select the enemy by running the target sight over the enemy, and store the enemies in an array, until it hits the preset array limit. Once it does, it uses a “For” loop to fire off the number of shots, which will track the enemy in that array slot.
The problem is that arrays aren’t my strong point and can someone show me an example?
Edit:
The script semi works but it can’t set the target of the Homing shot and it can’t get the same enemy more than once. Any advice?
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Input.GetKeyDown("space") && canShotLock){
isShotLock = true;
}
if(isShotLock){
if(Input.GetKeyDown("x")){
// On raycast hit, if it's an enemy add it.
if(Physics.Raycast(transform.position, fwd, hit, 100)){
var hite = hit.transform;
print(hite);
if(hite.gameObject.CompareTag("Enemy")){
SLT[current] = hite;
print(SLT[current]);
current++;
}
}
}
if(Input.GetKeyUp("x")){
ShotLock();
}
}
function ShotLock(){
current = 0;
while (current < SLT.length){
//current = 0;
//Instanitate
print("Firing");
audio.PlayOneShot(HomingShot);
var slShot = Instantiate(Homing, transform.position, Quaternion.identity);
slShot.transform.GetComponent("Projectile").Target = SLT[current].transform;
slShot.rigidbody.AddForce(transform.forward * 10, ForceMode.Impulse);
current++;
yield WaitForSeconds(0.4);
}
canShotLock = false;
}