'INVOKE Do NOT PERMIT THE EXECUTION OF OTHER ROUTINES
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class JasonControler : MonoBehaviour
{
public string jsonURL;
private Animator anim;
public int indexphoto;
void Start()
{
anim = GetComponent<Animator>();
InvokeRepeating("Repet", 1f, 1f);
}
void Repet()
{
anim.SetInteger("EntraPhoto Index", (0));
StartCoroutine(getData());
}
IEnumerator getData()
{
Debug.Log("Processando Dados, Aguarde!");
WWW _www = new WWW(jsonURL);
yield return _www;
if (_www.error == null)
{
processJasonData(_www.text);
}
else
{
Debug.Log("Opps something went Wrong");
}
}
private void processJasonData(string _url)
{
JasonDataClass jsnData = JsonUtility.FromJson<JasonDataClass>(_url);
indexphoto = (jsnData.numeroPhoto);
if (indexphoto == (0))
{
anim.SetInteger("Rotate Index", Random.Range(0, 19));
Debug.Log("Rotate");
}
else
{
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Rotate Index"))
{
return;
}
else
{
anim.SetInteger("EntraPhoto Index", (indexphoto));
Debug.Log(indexphoto);
}
}
}
}
I´m trying to do a loop that receive an external variable from a dynamic json file and if it is (0) executes "Rotate Index" Animation if it receieves any other number > (0) the routine should excecutes the "EntraPhoto Index" Animation, but with envoke even spacing for more time the animation could be excetuted correctly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
