如何显示两个列表中的两个元素?

时间:2017-08-25 12:29:21

标签: c# list object unity3d

所以我制作了一个幸运之轮,并有一个奖品清单和一个奖品图像列表,所以我想在最后用奖品图像显示奖品。我设法显示奖品而不是奖品图片。 (显示屏位于车轮停止旋转时激活的面板上)

这是脚本:

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]);

    }
   }
}

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

1 个答案:

答案 0 :(得分: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]);
    }
}