Tester.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using ObjectScripts;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using UnityEngine;
  6. public class Tester : MonoBehaviour
  7. {
  8. List<GameObject> gameObjects;
  9. double updateRate;
  10. double counterRate;
  11. [SerializeField] GameObject prefab;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. gameObjects = new List<GameObject>();
  16. for (int i = 0; i < 10; i++)
  17. gameObjects.Add(Instantiate(prefab));
  18. updateRate = counterRate = 5;
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. if(counterRate > updateRate)
  24. {
  25. Parallel.ForEach(gameObjects, x =>
  26. {
  27. DataObject data = x.GetComponent<DataObject>();
  28. data.Handler.UpdateRate = (float)updateRate;
  29. data.SetNewTargetPos(new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500)));
  30. });
  31. counterRate = 0;
  32. }
  33. counterRate += Time.deltaTime;
  34. }
  35. }