Hi there!
I know, my question may sound too much generic, let me rush to the point...
Here's what I've got:
using UnityEngine;
using System.Collections;
using System.Collections.Generic; // this line is for using a List
//TAG: Respawn --- since this is what it's doing right now...
public class EnemySpawnList : MonoBehaviour {
private List spawnPoint = new List();// The List of Vector 3, since we will need only positions.
private int spawnIndex; // The index to pick a Random Item of the List
public Vector3 spawnDecided; // A variable to declare the Item our Index has picked.
private Vector3[] p = new Vector3[8]; //AWESOME TRICK: I don't wanna store var and then manually say list.add this... so I'm making an array in which I'll store all the Items I want
// Use this for initialization
void Start () {
p[0] = new Vector3(85, 12, 0);
p[1] = new Vector3(-85,12,0);
p[2] = -p[0];
p[3] = -p[1];
p[4] = new Vector3(85, 20, 0);
p[5] = new Vector3(-85,20,0);
p[6] = -p[4];
p[7] = -p[5];
spawnPoint.InsertRange(0, p); // And then I Add all of them in my List, with just this line here... Majestic!
print ("Item's in my List: " + spawnPoint.Count);
}
// Update is called once per frame
void Update () {
spawnIndex = Random.Range (0,7);
TheFinalSpawnPoint();
}
public void TheFinalSpawnPoint(){
spawnDecided = spawnPoint[spawnIndex]; // WATCH IT: SquareBrackets!
}
}
I'm looking forward to make a Shuffle Bag out of this List(spawnPoint).
Right now my enemies instantiate at a static vector picked up by my spawnDecided... that's good.
Do you think it would be wise to change every Update the Items of Array p?
Say I'd like my enemies to spawn nearby the player, and to keep spawning nearby him even if he moves away, always at the same distances.
Right now my enemies are uncapable of doing that, but what if I say that p[0] = new Vector3 ( myTarget.position.x + 85, myTarget.position.y +12, 0) and so on?
Is that a wise method to achieve the result? I would have to assign those values in the Update though, wouldn't that be bad?
Could you please point me in the right direction? because at the very moment, I'm clueless... I just have a few suppositions which point to the way of how a MMORPG stores the speed/velocity of every player, predicting their next position and then recalculating possible errors...
Since I don't need to update this spawnIndex every frame, just only everytime an instantiate occurs ( which right now occurs every 5 seconds), I could store both the changing values of array p and spawnIndex into functions that run every n seconds... what about that?
I'm sorry I can't be anymore specific than that, I'm still pretty new to program, and because of that, would you mind being exhaustive in your answers? Please? Many thanks for your time!
P.S.: constuctive critics to my code are appreciated too!
↧