To select exact spawn positions for each of my enemy, I’m currently using the CopyTransform script but I feel like I could do it in a much more efficient way. I have binded the copy tool to hotkey ‘g’, and then the position is printed in the console using Debug.Log but I have to select the output in the console, then mark the position and finally copy it.
It’s a bit tedious and I was hoping someone could help me figure out how to maybe even copy the position with the hotkey so I could only paste it straight away, and anywhere. If that’s not possible, can I at least mark the top message in the console via script?
Edit: found this code and it works perfectly!
TextEditor te = new TextEditor();
te.content = new GUIContent(position.ToString());
te.SelectAll();
te.Copy();
That’s how I do it currently, and thanks to the great community now I will only have to press ‘g’ to copy the position of an object and then I can paste it inside my script.
Currently it’s a mess with every new enemy having the spawn position and rotation in the instantiate line, but I dunno if a list would make it much clearer. I want unique spawn points for each character.
do you have a map or a “area” where the enemy should spawn ? and random points would fit your needs ? Or do you want to delcare some fix spawn points in a list in inspector
so something like that would fit your needs: it’s a bit dirty, also you have to look that your enemy array is the same length as your spawnpoints but that’s just a little example what you could do
public class EnemySpawner : MonoBehaviour {
Vector3[] spawnPoints = new Vector3[] {
new Vector3(0f,0f,0f), //Spawnpoint 1
new Vector3(1f,1f,1f), //Spawnpoint 2
new Vector3(2f,2f,2f), //Spawnpoint 3
new Vector3(3f,3f,3f) //Spawnpoint 4
};
GameObject[] enemys;
[SerializeField] GameObject archer; //Here You can assign your enemy Prefabs
[SerializeField] GameObject gunner; //Here You can assign your enemy Prefabs
[SerializeField] GameObject tank; //Here You can assign your enemy Prefabs
int spawnIndex = 0;
GameObject enemyCharacter;
void Awake() {
// Assigning a SpawnOrder related to your Spawnpoints
enemys = new GameObject[] {
archer, //spawn for spawnpoint 1
gunner, //spawn for spawnpoint 2
tank, //spawn for spawnpoint 3
gunner //spawn for spawnpoint 4
};
}
void Update() {
if (spawnIndex < enemySpawner.Length) {
if (Input.GetKeyDown(KeyCode.G)) {
enemyCharacter = Instantiate(enemys[spawnIndex], spawnPoints[spawnIndex], identityQuaternion) as GameObject;
spawnIndex++;
}
}
}
}
you also can make it with list or queue . Also possible to make it useable in inspector so you can asign values there and add new spawns.
or you can write an EditorScript where you can assign everything in a nice way
Yea no problem, but i still can’t imagine what your are doing with this code
TextEditor te = new TextEditor();
te.content = new GUIContent(position.ToString());
te.SelectAll();
te.Copy();
and wy you have to copy something from your console using Debug.Log. to have your spawning positions.
you shouldn’t use stuff from console output to use in your code. ltttle bit inconvenient
but if it works for you, (does this also work on android iOS device ,windows build) or do you have tested it only in unity itself ? would be interesting to know
I use that code to copy the position of an object in the editor, so I just have to move the object around to find suitable spawn locations and then I copy the position to my spawning script. Since I want very specific placements of the units I use this method.
The unit is not spawned with ‘g’, it’s simply a hotkey to copy the position of a gameobject when using the editor.
I don’t have to use the Debug.Log copy since finding the code to copy to the windows clipboard.