For me the platform is moving…But the instantiated obstacles are not moving!Please help
Platform:
[SerializeField] float objSpeed = 1;
[SerializeField] private float startPos;
[SerializeField] private float resetPos;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
public void FixedUpdate ()
{
transform.Translate(Vector3.back * (objSpeed * Time.deltaTime));
if (transform.localPosition.z <= resetPos)
{
Vector3 newPos = new Vector3(transform.position.x, transform.position.y, startPos);
transform.position = newPos;
}
}
}
Obstacle:
void Start ()
{
StartCoroutine(WaitSpawner());
}
IEnumerator WaitSpawner()
{
yield return new WaitForSeconds(startWait);
while (!stop)
{
ranVar = Random.Range(0, 2);
if (ranVar == 0)
{
Vector3 spawnPos = new Vector3(obsPos[ranVar].x, obsPos[ranVar].y, Random.Range(1.5f, 2.5f));
obj = Instantiate(obstacle, spawnPos, obstacle.transform.rotation) as GameObject;
obj.transform.Translate(Vector3.back * (objSpeedd * Time.deltaTime));
Destroy(obj, 5f);
yield return new WaitForSeconds(spawnWait);
}
else
{
Vector3 spawnPos = new Vector3(obsPos[ranVar].x, obsPos[ranVar].y, Random.Range(1.5f, 2.5f));
obj = Instantiate(obstacle, spawnPos, obstacle.transform.rotation) as GameObject;
obj.transform.Translate(Vector3.back * (objSpeedd * Time.deltaTime));
Destroy(obj, 5f);
yield return new WaitForSeconds(spawnWait);
}
}
}
// Update is called once per frame
void Update()
{
spawnWait = Random.Range(spawnLeastWait, spawnMaxWait);
}