- Home /
Question by
supbruh · Mar 05, 2015 at 11:18 AM ·
c#instantiatespeedlevel
change speed of instantiated prefab
i want to increase the speed of instantiated prefab gradually as time progresses.Here is the code i tried which of course didn't work. Please help me with the code and could you tell me what i am doing wrong as well?Any Help is much appreciated!!
using UnityEngine; using System.Collections;
public class ChangeSpeed : MonoBehaviour { float speed=5f; // speed is supposed to increase as time increases. float spawnTime= Time.time; public GameObject[] bonuses; public float maxWidth; public float minWidth;
void Update () {
Vector3 bonusPos = new Vector3 (Random.Range (minWidth, maxWidth), transform.position.y, 0f);
float bonusNumber= Random.Range (0,1);
if (spawnTime > 7f)
{
GameObject myBonus= (GameObject) Instantiate (bonuses [bonusNumber], bonusPos, Quaternion.identity);
myBonus.transform.Translate (-Vector2.up*speed*Time.deltaTime);
}
}
}
Comment
Answer by Woj_Gabel_FertileSky · Mar 05, 2015 at 11:21 AM
public IEnumerator MakeSpheare()
{
float timeOfWait = 10f;
for(int i = 0 ; i < 10 ; i++)
{
Instantiate (object, position, rotation);
timeOfWait -= 1f;
yield return new WaitForSeconds(timeOfWait);
}
}
Your answer
Follow this Question
Related Questions
Creating a level from a textfile 0 Answers
Multiple Cars not working 1 Answer
Optimisation for 3D level creation 0 Answers
Distribute terrain in zones 3 Answers