void nextQuestion()
    {
        attempts = 0;
        corrects = 0;

        dataManager.fetchNextQuestionData();
        totalSlots = dataManager.currentSlots;

        ArrayList animalsForLevel = new ArrayList();

        foreach (Hashtable animalStr in availableAnimals)
        {
            animalsForLevel.Add(animalStr);
        }
        animalsForLevel = MAConstants.ShuffleList(animalsForLevel);

        int animalRequired = totalSlots / 2;

        while (animalsForLevel.Count > animalRequired)
        {
            animalsForLevel.RemoveAt(0);
        }

        ArrayList tempAnimals = new ArrayList();

        string    slotStr          = string.Format("{0}", totalSlots);
        Hashtable currentPositions = (Hashtable)allPositions[slotStr];


        foreach (Hashtable animalData in animalsForLevel)
        {
            for (int i = 0; i < 2; i++)              //create two of every kind
            {
                GameObject animalObj    = Instantiate(Resources.Load("JWMemoryAnimals/Prefabs/Animal")) as GameObject;
                MAAnimal   animalScript = animalObj.GetComponent <MAAnimal>();
                animalScript.setAnimal(animalData);
                animalObj.transform.parent = allAnimalsObj.transform;
                tempAnimals.Add(animalObj);
            }
        }

        animals = MAConstants.ShuffleList(tempAnimals);

        foreach (GameObject animalObj in animals)
        {
            string    indexStr = string.Format("{0}", animals.IndexOf(animalObj));
            Hashtable pos      = (Hashtable)currentPositions[indexStr];
            Vector3   position = new Vector3(MAConstants.GetAsFloat(pos["x"]), MAConstants.GetAsFloat(pos["y"]));
            animalObj.transform.localPosition = position;
        }

        Invoke("hideAll", 1.0f);
    }
Beispiel #2
0
    public void setAnimal(Hashtable animalData)
    {
        string name   = (string)animalData["name"];
        float  scaleX = MAConstants.GetAsFloat(animalData["x"]);
        float  scaleY = MAConstants.GetAsFloat(animalData["y"]);

        scaleX = 325F * 0.7f;
        scaleY = 250F * 0.7f;

        gameObject.name = name;

        string imageName = string.Format("JWMemoryAnimals/Sprites/{0}", name);

        animalBody.renderer.material.mainTexture = (Texture2D)Resources.Load(imageName);
        animalBody.transform.localScale          = new Vector3(scaleX, scaleY, 1);

        onlyBody();
    }