所以我制作了一个幸运之轮,并且有一个奖品列表和奖品图像的列表,所以我想在最后显示奖品和奖品图像。我设法显示奖品,但不显示奖品图像。(显示屏位于当车轮停止旋转时激活的面板上)
下面是脚本:
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]);
}
}
}如果有人能帮上忙,我会很高兴!
发布于 2017-08-29 18:53:50
使用Dictionary存储奖品和图像数据。您可以获得如下值:
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]);
}
}https://stackoverflow.com/questions/45881483
复制相似问题