2017-08-25 79 views
0

所以我即将制作一个幸运之轮,并且有奖品清单和奖品图片清单,所以我想在奖品结尾展示奖品。我设法显示奖品,但不是奖品图像。 (显示器是激活一个面板上,当车轮停止旋转)如何显示两个列表中的两个元素?

这里是脚本:

using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
using UnityEngine.UI; 
using UnityEngine.SceneManagement; 
public class SpinWheel : MonoBehaviour 
{ 
public List<string> Premio = new List<string>(); 
public List<AnimationCurve> animationCurves; 
public List<GameObject> ImagenPremio = new List<GameObject>(); 
public Text itemNumberDisplay; 
private bool spinning; 
private float anglePerItem; 
private int randomTime; 
private int itemNumber; 
public GameObject RoundEndDisplay; 
void Start() 
{ 
    spinning = false; 
    anglePerItem = 360/Premio.Count; 
    itemNumberDisplay.text = ""; 
} 
void Update() 
{ 
    if (Input.GetKeyDown(KeyCode.Mouse0) && !spinning) 
    { 
     randomTime = Random.Range(1, 4); 
     itemNumber = Random.Range(0, Premio.Count); 
     float maxAngle = 360 * randomTime + (itemNumber * anglePerItem); 
     StartCoroutine(SpinTheWheel(5 * randomTime, maxAngle)); 
    } 
} 
IEnumerator SpinTheWheel(float time, float maxAngle) 
{ 
    spinning = true; 
    float timer = 0.0f; 
    float startAngle = transform.eulerAngles.z; 
    maxAngle = maxAngle - startAngle; 
    int animationCurveNumber = Random.Range(0, animationCurves.Count); 
    Debug.Log("Animation Curve No. : " + animationCurveNumber); 
    while (timer < time) 
    { 
     //to calculate rotation 
     float angle = maxAngle * 
animationCurves[animationCurveNumber].Evaluate(timer/time); 
     transform.eulerAngles = new Vector3(0.0f, 0.0f, angle + startAngle); 
     timer += Time.deltaTime; 
     yield return 0; 
    } 
    transform.eulerAngles = new Vector3(0.0f, 0.0f, maxAngle + startAngle); 
    spinning = false; 
    Debug.Log("Premio: " + Premio[itemNumber]); 
    if (spinning == false) 
    { 
     yield return new WaitForSeconds(1); 
     RoundEndDisplay.SetActive(true); 
     itemNumberDisplay.text = ("Premio: " + Premio[itemNumber]); 

    } 
    } 
} 

我会很高兴,如果有人能帮助!

+0

你的变量'旋转'看起来像是浪费空间。由于'Update'只被调用一次,它实际上并没有做任何事情。如果'Update'和'SpinTheWheel'同时运行,我可以看到它是如何有用的。但是,这也需要改变你使用它的方式。 –

+0

是ImagenPremio您的图像奖励列表?他们是否都隐藏着附有精灵的gameobjects?为什么不使用'ImagenPremio [itemnumber] .SetActive(true);' – ryeMoss

+0

我不认为我理解你的问题。简单地把'setActive'部分放在'itemNumberDisplay.text;' – ryeMoss

回答

0

使用字典存储奖品和图像数据。 你可以得到这样的值:

public Dictionary<string, GameObject> Premio; 


private void Show(int itemNumber) 
{ 
    Debug.Log("Premio: " + 
       Premio.Keys.ToList()[itemNumber] + 
       Premio[Premio.Keys.ToList()[itemNumber]); 

} 

private void ShowAll() 
{ 
    foreach(var key in Premio.Keys) 
    { 
      Debug.Log("Premio: " + key + Premio[key]); 
    } 
} 
相关问题