Help Regarding 2D Spawning of Powerups...
Hi!!!! I am creating a 2D project.....
The Following are the Objects Used 1) Player - Gameobject 2) Spawn Location - Array 3) Max & Min Range - Int 4) Powerup - Gameobject
From last one week i am stuck with this issue.... ---> I want to spawn the powerup at random location.. but need to check if the player reaches the nearest spawnlocation... But the powerup should only spawn once.... And as the player collects the Powerup the spawn location should get reset and again the second nearest location should get set in the spawnlocation array....
Code:-
if (spawnpointreset == false)
{
spawnlocation = spawnpoint[UnityEngine.Random.Range(0 , spawnpoint.Length)];
spawnpointreset = true;
}
Vector2 playerPos = Player.transform.position;
Vector2 spawnpos1 = spawnlocation.transform.position;
if ((Vector2.Distance (playerPos, spawnpos1) <= maxrange) && spawned == false)
{
Debug.Log ("Hey Spawn Manager is Working");
powerupspawn (); // as the spawn should only do work once.. and reset the spawn location....
}
}
void powerupspawn()
{
Instantiate (powerup, spawnlocation.transform.position, spawnlocation.transform.rotation);
spawned = true;
spawnpointreset = false;
}
}
Your answer
Follow this Question
Related Questions
Rotating weapon in top-down 2D 0 Answers
How do I change the image of an SVG sprite? 0 Answers
Input.GetButtonDown("Jump") doesn't work 0 Answers
Why do prefabs overlap each other? 0 Answers
Boss ai help EoW 0 Answers