Hi,I am trying to grab a list from script ob1 every 5 seconds,The ob1 script i am grabbing from is updating every second,So i am expecting to see my second list length updating by 5 every 5 seconds,the first iteration works then it updates every second.
I can’t work out why please heeeeelp meeeee.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class grabList : MonoBehaviour
{
public GameObject go;
public List<int> grabTheList;
float timer;
// ob1Test ob;
// Start is called before the first frame update
void Start()
{
timer = Time.time + 5;
}
// Update is called once per frame
void Update()
{
if (Time.time > timer){
print("grabbbing");
timer = Time.time + 5;
grabTheList = new List<int>();
grabTheList = ob1Test.ints;
//grabTheList= ob.ints;
// grabTheList = go.GetComponent<ob1Test>().ints;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ob1Test : MonoBehaviour
{
public static List ints;
private int counter;
float timer;
// Start is called before the first frame update
void Start() {
// print(“running start”);
ints = new List();
}
// Update is called once per frame
void Update()
{
if (Time.time>timer){
timer = Time.time + 1;
ints.Add(counter);
counter++;
}
}
}