UniRxIntervalTest
You should now find a UniRx
folder in your project:
Cube
app
game object and call it ‘App’using System;
using UniRx;
using UnityEngine;
public class App : MonoBehaviour
{
public GameObject Cube;
private IDisposable _update;
void Start()
{
_update = Observable.Interval(TimeSpan.FromMilliseconds(1000)).Subscribe(x => // x starts from 0 and is incremented everytime the stream pushes another item.
{
Cube.transform.rotation = UnityEngine.Random.rotation;
});
}
private void OnDestroy()
{
_update.Dispose();
}
}
In the code above, the result of Observable.Interval
(an IDisposable
) is stored in a member to properly dispose when the MonoBehavior is destroyed.