I’m creating a List of game objects and I want to sway them back and forth randomly and slower than Mathf.PingPong allows. This is the code I have made so far and I am looking to sway each object in the list individually and to slow down the sway of Mathf.PingPong.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class GameObject: MonoBehaviour {
public List<GameObject> gameList = new List<GameObject>();
public GameObject goPrefab;
private float listSize = 500.0f;
private float time;
void Start () {
for (int i = 0; i < listSize; i++) { //andom.Range (0, 250)
Vector3 startPosition = new Vector3(Random.Range (-45, 140), 13, Random.Range(-60, 60));
GameObject rays = Instantiate(goPrefab, position, transform.rotation * Quaternion.Euler(0, 100, 100)) as GameObject;
rays.transform.parent = transform;
gameList.Add(rays);
}
}
void Update () {
time -= Time.deltaTime;
//Sway back and forth
transform.position = new Vector3(Mathf.PingPong(time, 1), transform.position.y, transform.position.x);
}
}