2017-02-28 8 views
0

現在、私はガンジープロジェクトのクイズのようなゲームを開発しています。プレイヤーがいくつかの得点に達したときに実際のゲームをフリーズして質問を表示させます。答えが正しければ、プレーヤーのスピードが上がります。そして、それはループで起こります。ユニティで繰り返されることなくランダムなデータを生成する方法C#

ここでは、質問を繰り返さないようにインデックスシーンを読み込むためにloadsceneを使用しています。ここでの問題は、シーンがロードされているときにクイズ部分をリロードするのではなく、ゲーム全体をリロードすることです。それを行う方法はありますか?何がやりたいことは、私はまた、二つの方法UserSelectTrueUserSelectFalseを組み合わせたでしょう、次のよう

IEnumerator TransitionToNextFact() 
{ 
    unansweredfacts.Remove(currentfacts); // remove the last shown question for the list 
    canvasquiz.SetActive(false); // disables the quiz canvas until the next question 
    yield return new WaitForSeconds(TimeBetweenFacts); 

    SetCurrentfact(); // sets the next random question from the list 
    canvasquiz.SetActive(true); // show the quiz canvas along with the new question 
} 

にTransitionToNextFact方法を変更され

シーンを再びロード
public class GameManager : MonoBehaviour 
{ 
    public Question[] facts; 
    private static List<Question> unansweredfacts; 
    private Question currentfacts; 

    [SerializeField] 
    private Text FactText; 

    [SerializeField] 
    private float TimeBetweenFacts = 3f; 

    [SerializeField] 
    private Text TrueAnswerText; 

    [SerializeField] 
    private Text FalseAnswerText; 

    [SerializeField] 
    private Animator animator; 

    [SerializeField] 
    public GameObject canvasquiz; 

    void Start() 
    { 
     if (unansweredfacts == null || unansweredfacts.Count == 0) 
     { 
      unansweredfacts = facts.ToList<Question>(); 
     } 
     SetCurrentfact(); 
     Debug.Log(currentfacts.Fact + "is" + currentfacts.IsTrue); 
    } 

    void SetCurrentfact() 
    { 
     int RandomFactIndex = Random.Range(0, unansweredfacts.Count); 
     currentfacts = unansweredfacts[RandomFactIndex]; 
     FactText.text = currentfacts.Fact; 
     if (currentfacts.IsTrue) 
     { 
      TrueAnswerText.text = "CORRECT !"; 
      FalseAnswerText.text = "WRONG !"; 
     } 
     else 
     { 
      TrueAnswerText.text = "WRONG !"; 
      FalseAnswerText.text = "CORRECT !"; 
     } 
    } 

    IEnumerator TransitionToNextFact() 
    { 
     unansweredfacts.Remove(currentfacts); 
     yield return new WaitForSeconds(TimeBetweenFacts); 
     SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); 
    } 

    public void UserSelectTrue() 
    { 
     animator.SetTrigger("True"); 
     if (currentfacts.IsTrue) 
     { 
      Debug.Log("CORRECT !"); 
     } 
     else 
     { 
      Debug.Log("WRONG !"); 
     } 
     StartCoroutine(TransitionToNextFact()); 
    } 

    public void UserSelectFalse() 
    { 
     animator.SetTrigger("False"); 
     if (!currentfacts.IsTrue) 
     { 
      Debug.Log("CORRECT !"); 
     } 
     else 
     { 
      Debug.Log("WRONG !"); 
     } 
     StartCoroutine(TransitionToNextFact()); 
    } 
+0

[Randomize a List ](http://stackoverflow.com/questions/273313/randomize-a-listt) –

答えて

1

基本的にはそれを再起動し、

public void UserSelected(bool isTrue) 
{ 
    animator.SetTrigger(isTrue ? "True" : "False"); 
    if (currentfacts.IsTrue == isTrue) 
    { 
     Debug.Log("CORRECT !"); 

    } 
    else 
    { 
     Debug.Log("WRONG !"); 

    } 


    StartCoroutine(TransitionToNextFact()); 
} 
+0

ありがとうございました!私を助けてくれました。私が直面した唯一の問題は、何らかの理由でメソッドUserSelected()がアニメーションをトリガーせず、クルーチンを開始するということです。しかし、私が以前のメソッドUserSelectTrue()とUserSelectFalse()を使用するとうまくいきます。問題はIsTrue.ToString()にあると思います。 – METEOARA

+0

全く問題ありません!私は答えを編集した、それは間違いなくトリガーの問題を修正する必要があります。この回答が参考になった場合は、それをマークすることを検討してください:) –

+0

申し訳ありません。すべてうまく動作します。私の間違いは、On Click()でメソッドを追加するのを忘れてしまったことです。 – METEOARA

関連する問題