“This is the 20th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

👉 About the author

As we all know, life is a long process of constantly overcoming difficulties and reflecting on progress. In this process, there will be a lot of questions and thoughts about life, so I decided to share my thoughts, experiences and stories to find resonance!!

Focus on Android/Unity and various game development tips, as well as various resource sharing (websites, tools, materials, source code, games, etc.)

Welcome to pay attention to the public account [Mr. Empty name] for more resources and communication!

👉 premise

[This trump card, we are about to enter the main interface of the game]

👉 Practice

😜 Game main interface

After the first two sections, here we have the start page, and then it’s time to start the game.

Let’s first analyze the specific gameplay:

  • 1. Preview the next ball content style in the upper right corner of the page
  • 2. No new ball shall be released before the current ball falls to prevent it from being too fast
  • 3. The left and right bottom sides are not allowed to exceed the boundary, there are barriers (collision shoulder wipe)
  • 4. The ball has the property of free fall and the appropriate rebound effect
  • 5. Play the appropriate audio and merge effects during the ball merge
  • 6. Lose decisions and scores should be displayed when crossing the upper boundary
  • 7. You can restart the game and return to the home page

So we added a background, a left wall, a right wall, and the ground at the bottom, just enough to cover the back.

Add a BoxCollider2D and a RigidBody2D component to the wall in order to keep objects inside the wall from falling out of bounds.

😜 implement return and replay

Before making the scene change, both of them need to determine whether the current score is greater than the historical high score, if so, save the current score and replace it, otherwise they can leave it alone. Then use [director. LoadScene] to load the scene.

Oh, and don’t forget to specify click events for buttons in the scene.

// Replay the game
GameRePlay() {
    // Also decide whether to save the data
    let MaxScore = localStorage.getItem(ScriptStatic.MaxScore);
    if(MaxScore ! =null) {
        // Compare the current score with the saved score
        //parseInt The second argument represents the base
        if (parseInt(MaxScore.toString(), 10) < ScriptStatic.CurrentScore) {
            localStorage.setItem(ScriptStatic.MaxScore, ScriptStatic.CurrentScore + ""); }}// Save the score above
    ScriptStatic.CurrentScore=0;
    director.loadScene("scene_game");
}


// Return to the previous scene
ClickBack() {
    let MaxScore = localStorage.getItem(ScriptStatic.MaxScore);
    if(MaxScore ! =null) {
        // Compare the current score with the saved score
        //parseInt The second argument represents the base
        if (parseInt(MaxScore.toString(), 10) < ScriptStatic.CurrentScore) {
            localStorage.setItem(ScriptStatic.MaxScore, ScriptStatic.CurrentScore + "");
        }
    }
    director.loadScene("scene_start");
}
Copy the code

👉 other

📢 author: Kom and Kom in Kom

📢 reprint instructions – be sure to specify the source: Zhim Granular’s personal home page – column – Nuggets (juejin. Cn)

📢 welcome to like 👍 collect 🌟 message 📝