Nội dung bài viết ♥
- Tạo các folder và đưa file tài nguyên
- Thêm background và Button
- Xử lý button
I. Tạo các Folder và tài nguyên
- Trong mục Assets bạn tạo các folder cần thiết: Animations, Prefabs, Scripts và kéo file tài nguyên Resources vào.
- Tải file tài nguyên "tại đây"
II. Thêm background và button
- Trong Scences tạo Menu và Level1, kích double vào scences Menu và kéo background vào
- Tạo Button bằng cách GameObject - UI - Button, tại màn hình scence thu nhỏ lại và kéo Button và vị trí cần đặt.
- Click vào Button - Image(Script) - Source Image - Chọn Image cho Button.
- Đê xóa chữ Button vào Text - xóa
III. Xử lý Button chuyển cảnh
- Trong mục Script tạo file script StartLevel để chạy game
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class StartLevel : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void StartLevel1(){
SceneManager.LoadScene("Level1");
}
}
- Kéo script StartLevel vào ButtonPlay trong phần Add Component.
- Trong phần onClick của buttonPlay - click dấu Cộng(+) rồi chọn btnPlay
- Trong phần No Function chọn hàm StartLevel1 đã tạo trong script.
- Cuối cùng là build các Scences đã tạo, click vào scences Level1 - File - Build Setting - Add Open scences
- Cuối cùng là Play và ấn vào nút Play để chuyển từ scences Menu sang scences Level 1
0 nhận xét:
Đăng nhận xét
Thank you!