Unity MiniFutbol
Source: Dev.to
1. Maydon poli (Plane)
- Hierarchy → Right‑click → 3D Object → Plane
- Inspector settings:
- Name:
Ground - Position: X = 0, Y = 0, Z = 0
- Scale: X = 2, Y = 1, Z = 3
- Name:
2. Yashil material yaratish
- Project → Right‑click → Create → Material
- Name:
GrassMaterial - Inspector → Albedo: 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 Object → Cube
- Inspector:
- Name:
WallLeft - Position: X = ‑10, Y = 0.5, Z = 0
- Scale: X = 0.2, Y = 1, Z = 30
- Name:
3.2 O’ng devor
- Hierarchy → Right‑click → 3D Object → Cube
- Inspector:
- Name:
WallRight - Position: X = 10, Y = 0.5, Z = 0
- Scale: X = 0.2, Y = 1, Z = 30
- Name:
3.3 Orqa devor (o’yinchi tomoni)
- Create Cube → Name:
WallBack - Position: X = 0, Y = 0.5, Z = ‑15
- Scale: X = 20, Y = 1, Z = 0.2
3.4 Old devor (raqib tomoni)
- Create Cube → Name:
WallFront - Position: X = 0, Y = 0.5, Z = 15
- Scale: X = 20, Y = 1, Z = 0.2
3.5 Devorlar uchun material
- Create → Material → Name:
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
- Hierarchy → 3D Object → Sphere
- Inspector:
- Name:
Ball - Position: X = 0, Y = 0.5, Z = 0
- Scale: X = 0.5, Y = 0.5, Z = 0.5
- Name:
4.2 To’p materiali
- Create → Material → Name:
BallMaterial - Albedo: white
- Apply to the Ball object.
4.3 Fizika qo’shish
- Select Ball → Inspector → Add Component → Rigidbody
- Rigidbody settings:
- Mass: 0.5
- Drag: 0.5
- Angular Drag: 0.5
- Use Gravity: ✅
4.4 To’p uchun Physics Material
- Project → Create → Physics Material → Name:
BallPhysics - Inspector:
- Dynamic Friction: 0.6
- Static Friction: 0.6
- Bounciness: 0.3
- Friction Combine: Average
- Bounce Combine: Average
- Select Ball → Rigidbody → Material → assign BallPhysics.
5. Player (Capsule) yaratish
5.1 Player obyektini qo’shish
- Hierarchy → 3D Object → Capsule
- Inspector:
- Name:
Player - Position: X = 0, Y = 1, Z = ‑10
- Scale: X = 1, Y = 1, Z = 1
- Name:
5.2 Player materiali
- Create → Material → Name:
PlayerMaterial - Albedo: blue
#0066FF - Apply to the Player object.
5.3 Fizika qo’shish
- Select Player → Add Component → Rigidbody
- 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
- Select the Ball object.
- In the Inspector, click the Tag dropdown → Add Tag… → + → Name:
Ball. - 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)
- Drag the
CameraFollowscript onto Main Camera. - 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)
- Hierarchy → Create Empty → Name:
GoalPlayer - Position: X = 0, Y = 0, Z = ‑14
Inside GoalPlayer, create three Cube objects and assign a material:
- Create → Material → Name:
GoalPostMaterial→ Albedo: 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 GoalPlayer → Right‑click → 3D Object → Cube
- 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
GoalPlayerandGoalAI(if they don’t exist). - Assign
GoalPlayertag to GoalTriggerPlayer andGoalAItag 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.csscript 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)
- Canvas → Right‑click → UI → Text → Name:
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
- Text:
12.3 AI skori (o’ng yuqori)
- Canvas → Right‑click → UI → Text → Name:
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
- Text:
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
- Player Score Text: drag
✅ 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
- Hierarchy → Right‑click → UI → Canvas
14.3 Tugmalar
- Inside the Canvas: Right‑click → UI → Button - TextMeshPro (create START, EXIT, etc.).
14.4 MenuManager scripti
- Add a
MenuManagerscript 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:
MainMenu(index 0)GameScene(index 1)
✅ Test: Run the game from the MainMenu scene.
16. Pause Menu
16.1 Pause UI
- Open GameScene → Hierarchy → Right‑click → UI → Canvas
- 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
PausePaneland disable it by default (uncheck the GameObject).
16.3 PauseManager scripti
- Attach a
PauseManagerscript to the Canvas. - Configure the buttons:
- RESUME:
PauseManager.ResumeGame() - MENU: load MainMenu scene
- RESTART: reload the current game scene
- RESUME:
✅ Test: Press ESC during gameplay → Pause menu appears.
- RESUME continues the game.
- MENU returns to MainMenu.
- RESTART restarts the game.