Hello, im making space shooter game and I need help with spawning “minerals”. When I destroy asteroid(kill) there is a chance that it will spawn mineral. This works BUT it spawns at 0,0,0 (asteroid prefab coordinates) how can I make them spawn at spawned(clone) asteroid?
public void OnEnemyJustDied()
{
if (Random.Range(0f, 1f) <= m_dropChance)
{
Debug.Log("spawned");
Instantiate(mineralPrefab, transform.position, transform.rotation);
}
}
const float m_dropChance = 1f / 10f;
}
here is my asteroid spawner.
void asteroidSpawning()
{
Vector3 spawnPos = new Vector3(Random.Range(-spawnX, spawnX), 0, spawnZ);
int asteroidIndex = Random.Range(0, asteroidPrefabs.Length);
Instantiate(asteroidPrefabs[asteroidIndex], spawnPos, asteroidPrefabs[asteroidIndex].transform.rotation);
}
thanks for help and sorry for my bad english.