Unity MiniFutbol

Published: (December 10, 2025 at 12:47 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

1. Maydon poli (Plane)

  • Hierarchy → Right‑click → 3D ObjectPlane
  • Inspector settings:
    • Name: Ground
    • Position: X = 0, Y = 0, Z = 0
    • Scale: X = 2, Y = 1, Z = 3

2. Yashil material yaratish

  • Project → Right‑click → CreateMaterial
  • Name: GrassMaterial
  • InspectorAlbedo: choose green #2D7A2F
  • Drag & drop the material onto the Ground object.

Natija: Yashil futbol maydoni tayyor!

3. Devorlarni qurish

3.1 Chap devor

  • Hierarchy → Right‑click → 3D ObjectCube
  • Inspector:
    • Name: WallLeft
    • Position: X = ‑10, Y = 0.5, Z = 0
    • Scale: X = 0.2, Y = 1, Z = 30

3.2 O’ng devor

  • Hierarchy → Right‑click → 3D ObjectCube
  • Inspector:
    • Name: WallRight
    • Position: X = 10, Y = 0.5, Z = 0
    • Scale: X = 0.2, Y = 1, Z = 30

3.3 Orqa devor (o’yinchi tomoni)

  • Create CubeName: WallBack
  • Position: X = 0, Y = 0.5, Z = ‑15
  • Scale: X = 20, Y = 1, Z = 0.2

3.4 Old devor (raqib tomoni)

  • Create CubeName: WallFront
  • Position: X = 0, Y = 0.5, Z = 15
  • Scale: X = 20, Y = 1, Z = 0.2

3.5 Devorlar uchun material

  • Create → MaterialName: WallMaterial
  • Albedo: choose gray or red
  • Apply the material to all four walls.

Natija: 4 ta devor bilan yopiq maydon!

4. To’p yaratish

4.1 To’p obyekti

  • Hierarchy3D ObjectSphere
  • Inspector:
    • Name: Ball
    • Position: X = 0, Y = 0.5, Z = 0
    • Scale: X = 0.5, Y = 0.5, Z = 0.5

4.2 To’p materiali

  • Create → MaterialName: BallMaterial
  • Albedo: white
  • Apply to the Ball object.

4.3 Fizika qo’shish

  • Select BallInspectorAdd ComponentRigidbody
  • Rigidbody settings:
    • Mass: 0.5
    • Drag: 0.5
    • Angular Drag: 0.5
    • Use Gravity:

4.4 To’p uchun Physics Material

  • ProjectCreatePhysics MaterialName: BallPhysics
  • Inspector:
    • Dynamic Friction: 0.6
    • Static Friction: 0.6
    • Bounciness: 0.3
    • Friction Combine: Average
    • Bounce Combine: Average
  • Select BallRigidbodyMaterial → assign BallPhysics.

5. Player (Capsule) yaratish

5.1 Player obyektini qo’shish

  • Hierarchy3D ObjectCapsule
  • Inspector:
    • Name: Player
    • Position: X = 0, Y = 1, Z = ‑10
    • Scale: X = 1, Y = 1, Z = 1

5.2 Player materiali

  • Create → MaterialName: PlayerMaterial
  • Albedo: blue #0066FF
  • Apply to the Player object.

5.3 Fizika qo’shish

  • Select PlayerAdd ComponentRigidbody
  • Rigidbody settings:
    • Mass: 2
    • Drag: 2
    • Angular Drag: 5
    • Use Gravity:
  • Constraints: Freeze Rotation on X, Y, Z.

5.4 Capsule Collider sozlash

  • The Player already has a Capsule Collider.
  • Radius: 0.5
  • Height: 2

Natija: Ko’k o’yinchi tayyor!

6. Tag qo’shish

6.1 Ball tagi

  1. Select the Ball object.
  2. In the Inspector, click the Tag dropdown → Add Tag…+Name: Ball.
  3. Save, then re‑select Ball and set its Tag to Ball.

6.2 Player tagi

  • Select Player, set Tag to Player.
  • If the tag does not exist, create it via Add Tag…Name: Player.

7. Kamera sozlash

  • Select Main Camera.
  • Transform:
    • Position: X = 0, Y = 15, Z = ‑12

7.1 Kamera scripti (CameraFollow)

  1. Drag the CameraFollow script onto Main Camera.
  2. In the script component:
    • Target: drag the Player object.
    • Offset: X = 0, Y = 15, Z = ‑12
    • Smooth Speed: 5

8. Darvozalar yaratish

8.1 O’yinchi darvozasi (pastda)

  • HierarchyCreate EmptyName: GoalPlayer
  • Position: X = 0, Y = 0, Z = ‑14

Inside GoalPlayer, create three Cube objects and assign a material:

  • Create → MaterialName: GoalPostMaterialAlbedo: white
  • Apply the material to all three cubes.

8.2 Raqib darvozasi (tepada)

  • Duplicate GoalPlayer (Ctrl + D).
  • Rename: GoalAI
  • Position: X = 0, Y = 0, Z = 14

Natija: 2 ta darvoza tayyor!

9. Goal Trigger yaratish

9.1 Player uchun trigger

  • Select GoalPlayerRight‑click3D ObjectCube
  • Name: GoalTriggerPlayer
  • Position: X = 0, Y = 1, Z = 0.5
  • Scale: X = 6, Y = 2, Z = 0.5

Trigger sozlash:

  • Add Box Collider → enable Is Trigger.
  • Disable Mesh Renderer (make it invisible).

9.2 AI uchun trigger

  • Copy GoalTriggerPlayer (Ctrl + C).
  • Select GoalAI, paste as child (Ctrl + V).
  • Rename: GoalTriggerAI
  • Position: X = 0, Y = 1, Z = ‑0.5

9.3 Tag qo’shish

  • Create tags GoalPlayer and GoalAI (if they don’t exist).
  • Assign GoalPlayer tag to GoalTriggerPlayer and GoalAI tag to GoalTriggerAI.

10. Goal System scripti

// GoalDetector.cs
using UnityEngine;

public class GoalDetector : MonoBehaviour
{
    private GameManager gameManager;

    void Start()
    {
        gameManager = FindObjectOfType();
    }

    // Add trigger handling logic here...
}
  • Attach GoalDetector to GoalTriggerPlayer and set Is Player Goal to ✅.
  • Attach another GoalDetector to GoalTriggerAI and leave Is Player Goal unchecked.

11. Game Manager (Score tizimi)

// GameManager.cs
using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public Text playerScoreText;
    public Text aiScoreText;
    public GameObject ball;

    // Implement scoring logic here...
}
  • Create an empty GameObject named GameManager.
  • Drag the GameManager.cs script onto it.

12. UI yaratish (Skor ko’rsatish)

12.1 Canvas sozlamalari

  • Render Mode: Screen Space – Overlay
  • Canvas Scaler → UI Scale Mode: Scale With Screen Size
  • Reference Resolution: 1920 × 1080

12.2 Player skori (chap yuqori)

  • CanvasRight‑clickUITextName: PlayerScoreText
  • Rect Transform:
    • Anchor: Top‑Left
    • Pos X: 100, Pos Y: ‑50
    • Width: 200, Height: 100
  • Text component:
    • Text: 0
    • Font Size: 72
    • Alignment: Center
    • Color: blue

12.3 AI skori (o’ng yuqori)

  • CanvasRight‑clickUITextName: AIScoreText
  • Rect Transform:
    • Anchor: Top‑Right
    • Pos X: ‑100, Pos Y: ‑50
    • Width: 200, Height: 100
  • Text component:
    • Text: 0
    • Font Size: 72
    • Alignment: Center
    • Color: red

12.4 GameManager ga UI bog’lash

  • Select GameManager → in the Inspector assign:
    • Player Score Text: drag PlayerScoreText
    • AI Score Text: drag AIScoreText
    • Ball: drag the Ball object

SINOV:

  • Gol urilganda skor ortadimi? ✅
  • To’p markazga qaytadimi? ✅
  • Skorlar ekranda ko’rinadimi? ✅

13. Scene saqlash

  • File → Save As… → give the scene an appropriate name (e.g., GameScene).

14. MainMenu Scene yaratish

14.1 Yangi scene

  • File → New Scene

14.2 UI qo’shish

  • HierarchyRight‑clickUICanvas

14.3 Tugmalar

  • Inside the Canvas: Right‑clickUIButton - TextMeshPro (create START, EXIT, etc.).

14.4 MenuManager scripti

  • Add a MenuManager script to the Canvas and configure the buttons (START → load game scene, EXIT → quit application).

15. Build Settings

  • File → Build Settings (Ctrl + Shift + B)
  • Add scenes in order:
    1. MainMenu (index 0)
    2. GameScene (index 1)

Test: Run the game from the MainMenu scene.

16. Pause Menu

16.1 Pause UI

  • Open GameSceneHierarchyRight‑clickUICanvas
  • Inside the Canvas, add a Panel (name it PausePanel).
  • Add Button objects under PausePanel (e.g., RESUME, MENU, RESTART).

16.2 PausePanel ni yashirish

  • Select PausePanel and disable it by default (uncheck the GameObject).

16.3 PauseManager scripti

  • Attach a PauseManager script to the Canvas.
  • Configure the buttons:
    • RESUME: PauseManager.ResumeGame()
    • MENU: load MainMenu scene
    • RESTART: reload the current game scene

Test: Press ESC during gameplay → Pause menu appears.

  • RESUME continues the game.
  • MENU returns to MainMenu.
  • RESTART restarts the game.
Back to Blog

Related posts

Read more »

My PC melted while making this game...

Background I've been watching a lot of MoistCr1TiKaL Gaming and Jacksepticeye videos lately. Seeing them play games that look like student projects inspired me...