- Home /
How to match the speed of objects and the spawn speed of objects?
HELP HELP HELP! Hello Unity Community. I'm new to Unity and to C#.I want to create a game for my practicing and i am stuck with a problem.
i want that the objects spawn and smoothly it increase the speed of spawning. and it the same time it increase the the movement speed of objects. and it don't find the gap in the middle and don't go inside of each other.
no problem if the code is in java Script.
just like DON'T TAP THE WHITE TILES game
`This is the code that i'm using for spawn the objects.`
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour
public float spawnWait = 0f;
public float startWait = 0f;
public GameObject[] spawnObjects;
// Use this for initialization
void Start ()
{
}
IEnumerator SpawnWaves()
{
while (true)
{
{
//Instantiate a random enemy.
int enemyIndex = Random.Range(0, spawnObjects.Length);
Instantiate(spawnObjects[enemyIndex], transform.position, Quaternion.identity);
yield return new WaitForSeconds (spawnWait);
}
}
}
void Update ()
{
if(spawnWait > 0)
{
spawnWait = spawnWait - 0.0001f;
}
}
}
This is the code that i'm using for the speed of objects using UnityEngine; using System.Collections;
public class Force : MonoBehaviour {
public float currentSpeed = 0.0f;
public float maxSpeed = 10.0f;
public float increaseValueOfSpeed =0.0f;
// Use this for initialization
void Start ()
{
}
void Update ()
{
transform.position+=(Vector3.down *Time.deltaTime*currentSpeed);
if(currentSpeed<maxSpeed )
{
currentSpeed+=increaseValueOfSpeed*Time.deltaTime;
}
}
}
thanks in advance for your help!!!!!
You write 'no problem if the code is in java Script.'
Does that mean you know how to do it in javascript but not in c#? If so, why not convert your javascript code to c#? If you get stuck somewhere, just post the part you don't know how to convert.
If that's not it, it's not very clear what your problem is exactly. You don't know how to do something in c#? What do you want to do? Or some c# code is not acting as you expect? What is your code, what do you expect it to do, and what does it actually do?
Thanks for quick reply no i don't know how to write JavaScript. I mean by no problem if the code is in JavaScript that i can convert JavaScript to C# (just if someone know the answer in JavaScript so that's why). And i am expecting from code to increase the speed of spawning and the speed of object moving down so that they don't find gap in the middle of each other and they don't go inside of each other.
i mean is soon the spawn speed go higher the object movement speed should go higher is well so there speed match with each others.
once again thanks for your reply.
So as you spawn new objects, do you want the speed of only those new objects to be faster than the previous objects or do you want the speed of all previously spawned objects to be sped up too?
OBJ # Spawn Time Speed of Object
1 0 1
2 10 2
3 18 3
4 24 4
**OR**
OBJ # Spawn Time Speed at 0 at 10 at 18 at 24
1 0 1 -> 2 -> 3 -> 4
2 10 2 -> 3 -> 4
3 18 3 -> 4
4 24 4
Save a reference to the last spawned item and measure its distance to where it spawned. If that's greater than it's height spawn the next one and move it where the distance to the former piece is exactly the height (without changing the spawn point of course). With this you can increase falling speed without problems and you would get the tiles without gaps.
Hi hexagonius thanks for your quick reply. can you please show me the code which code i can use for increasing the speed and spawning so that they don't find gap each others i mean by increasing speed that it increase the speed in the gameplay when it reach to specific time or score and then increase the speed and keep that speed. and is well the spawn time also match with the speed of objects falling..
Thanks..