- Home /
random spawn assigned prefab from collider
Hello I need an script that spawn a assigned prefab from al collider this must be random and the spawning must go faster and faster until the player dies
T27$$anonymous$$ its a beginning but it must be the whole time and it must go faster in time
Answer by VesuvianPrime · Jul 29, 2014 at 11:29 AM
Rick, typically you need to show some effort on your part before asking the community for help. You can't expect us to write your game for you.
Programming is a matter of breaking down a large problem into smaller pieces.
Your problem is:
"I need an script that spawn a assigned prefab from al collider this must be random and the spawning must go faster and faster until the player dies"
We can break this down into a number of small problems:
1) Assigning a prefab to a variable on a script.
2) Instantiating the prefab.
3) Instantiating the prefab in a random place.
4) Instantiation is on a timer, and must increase in frequency.
The video T27M posted is perfect, and addresses points 1&2 very well.
For point 3 we can look at the UnityEngine.Random class: http://docs.unity3d.com/ScriptReference/Random-insideUnitSphere.html
Point 4 is where things get a little more interesting.
Firstly, we should take a look at the script reference for Time: http://docs.unity3d.com/ScriptReference/Time.html
You're going to need to write some kind of emission timer to handle your instantiation intervals:
public class Emitter : MonoBehaviour
{
private float m_LastEmission;
// You'll need to adjust this line to get the rate you want
public abstract float emissionRate { get {return Time.time;} }
protected void Update()
{
float elapsed = Time.time - m_LastEmission;
int numEmissions = Mathf.FloorToInt(emissionRate * elapsed);
Emit(numEmissions);
if (numEmissions <= 0)
return;
float emissionTimePerInstance = 1.0f / emissionRate;
m_LastEmission += emissionTimePerInstance * numEmissions;
}
}
You have got everything you need! We can't help you any further if you won't help yourself. Start writing some code, it probably won't work, make it work, ask specific questions about that code, repeat.
Your answer
Follow this Question
Related Questions
Is it possible to make thousands of colliders at once? 1 Answer
Problem with random spawning and coroutine 1 Answer
Trouble with triggers and colliders 1 Answer
This melee damage detector won't work... 1 Answer
instantiating vertically 2 Answers