コード例 #1
0
    //SPAWN MUSHROOMS
    void SpawnMushrooms()
    {
        // If any mushrooms are found in the database
        if (mushroomCount > 0)
        {
            /* Stores the command in a string
             * The command selects the values from the player table which are for the character name selected inside the PlayerMainScript
             */
            string sqlQueryMushrooms = "SELECT mushID, posX, posY, posZ, currentAge, deathAge FROM MushroomsTable WHERE id = '" + charName + "';";

            dbcmd.CommandText = sqlQueryMushrooms;
            IDataReader readerMushrooms = dbcmd.ExecuteReader();

            while (readerMushrooms.Read())
            {
                //sets the results into variables
                int   mushroomID       = readerMushrooms.GetInt32(0);
                float mushroomPosX     = readerMushrooms.GetFloat(1);
                float mushroomPosY     = readerMushrooms.GetFloat(2);
                float mushroomPosZ     = readerMushrooms.GetFloat(3);
                float mushroomAge      = readerMushrooms.GetFloat(4);
                float mushroomDeathAge = readerMushrooms.GetFloat(5);

                /* Uses the CreateDBMushroom script, which is described inside the mushroom script
                 * in order to spawn the mushrooms loaded from the database
                 * Also displays their information into the console
                 */
                mushroomScript.CreateDBMushroom(mushroomID, mushroomPosX, mushroomPosY, mushroomPosZ, mushroomAge, mushroomDeathAge);
                Debug.Log("Mushroom Created. ID: " + mushroomID + " x = " + mushroomPosX + " y = " + mushroomPosY + " z = "
                          + mushroomPosZ + " Age: " + mushroomAge + " Death Age: " + mushroomDeathAge);
            }

            //closes the reader and makes sure it's null (debugging purposes)
            readerMushrooms.Close();
            readerMushrooms = null;
        }

        //Spawns random mushrooms
        else
        {
            mushroomScript.CreateMushrooms();
        }
    }