lundi 20 août 2018

An issue regarding to my android app in Unity3d(Random.Range and the app-life-cycle)

Good day,

I am coding a game for android, but I have an issue.

In my game you can open a chest, and so you can find characters 1-12. Normally everything works fine, but I don't want that a Player can find a character twice, so I coded this (I use Random.Range(-15,110) because I want to have different chances for the characters):

          using System.Collections;
          using System.Collections.Generic;
          using UnityEngine;

          public class CasinoThatItGoesFurther : MonoBehaviour {

              private int random = -100;

  //to get the prefabs
              public GameObject char1;
              public GameObject char2;
              public GameObject char3;
              public GameObject char4;
              public GameObject char5;
              public GameObject char6;
              public GameObject char7;
              public GameObject char8;
              public GameObject char9;
              public GameObject char10;
              public GameObject char11;
              public GameObject char12;



              void Update()
              {
      //chest disappears and the player gets a character
                  if (Var.clickedChest == 9)
                  {
                      random = Random.Range(-15, 110);
                      RandomChar();

                  }
      //if I buy another chest,that the shown character dissapears
                   else if (Var.chestBought == true) { 

                      char1.SetActive(false);
                      char2.SetActive(false);
                      char3.SetActive(false);
                      char4.SetActive(false);
                      char5.SetActive(false);
                      char6.SetActive(false);
                      char7.SetActive(false);
                      char8.SetActive(false);
                      char9.SetActive(false);
                      char10.SetActive(false);
                      char11.SetActive(false);
                      char12.SetActive(false);
                    }


              }


              void RandomChar()
              {

      //char1
                  if (random >= -15 & random <= 0 & Var.chestIs1 == false)
                  {
                      Var.chestIs1 = true;

      //that you can see which character you got
                      char1.SetActive(true);
                  }
      //when you get the character twice
                 else if (random >= -15 & random <= 0 & Var.chestIs1)
                      {
                          int random = Random.Range(-15, 110);
                      }



      //char2
                  if (random >= 1 & random <= 15 & Var.chestIs2 == false)
                  {
                      Var.chestIs2 = true;

      //that you can see which character you got
                      char2.SetActive(true);
                  }
      //when you get the character twice
                  else if (random >= 1 & random <= 15 & Var.chestIs2)
                      {
                          int random = Random.Range(-15, 110);
                      }



      //char3
                  if (random >= 16 & random <= 30 & Var.chestIs3 == false)
                  {
                      Var.chestIs3 = true;
                      char3.SetActive(true);
                  }
      //when you get the character twice
                  else if (random >= 16 & random <= 30 & Var.chestIs3)
                      {
                          int random = Random.Range(-15, 110);
                      }




      //char4
                  if (random >= 31 & random <= 40 & Var.chestIs4 == false)
                  {
                      Var.chestIs4 = true;
                      char4.SetActive(true);
                  }
      //when you get the character twice
                  else if (random >= 31 & random <= 40 & Var.chestIs4)
                      {
                          int random = Random.Range(-15, 110);
                      }




      //char5
                  if (random >= 41 & random <= 50 & Var.chestIs5 == false)
                  {
                      Var.chestIs5 = true;
                      char5.SetActive(true);
                  }
      //when you get the character twice
                  else  if (random >= 41 & random <= 50 & Var.chestIs5)
                      {
                          int random = Random.Range(-15, 110);
                      }




      //char6
                  if (random >= 51 & random <= 60 & Var.chestIs6 == false)
                  {
                      Var.chestIs6 = true;
                      char6.SetActive(true);
                  }
      //when you get the character twice
                  else if (random >= 51 & random <= 60 & Var.chestIs6)
                      {
                          int random = Random.Range(-15, 110);
                      }
          //........till character 12

            }
          }

The only thing what happens if I get a character twice is that, that the random number changes.

My problem in one sentence: If I get a character twice, nothing happens except that random changes, and so I have to buy f.e. 20 Chests, instead of 12, till chestIs1-12 is true.

Hopefully I wrote it clearly and someone can help me ^^.




Aucun commentaire:

Enregistrer un commentaire