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);
}
}
}