Nội dung bài viết ♥
- Trình soạn thảo script
- GameObject và script C#
- Debug
I. Trình soạn thảo script
- Trình soạn thảo trước đây của Unity là MonoDevelop và ngôn ngữ hỗ trợ là JavaScript.
- Nhưng hiện tại Unity đã ngừng hỗ trợ Javascript vì vậy bạn phải viết bằng ngôn ngữ C# cùng với trình soạn thảo Visual Studio Code.
- Để cấu hình script được mở bằng Visual Studio Code bạn vào Edit - Preferences - External Tools - Chọn Visual Studio Code
II. GameObject và script C#
- Đầu tiên hãy tạo GameObject
GameObject - Create Empty
- Trong GameObject đã được tạo - Nhấn Add Component - New script - HelloWorld để tạo file script dưới dạng C#.
- Bạn cũng có thể tạo file script bằng , sau đó kéo vào Component GameObject.
Click chuột phải Asset - Create - C# Script
III. Debug
- Trong file C#, sửa hàm start thành:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Introduction : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log("1 + 2 = " + (1+2));
}
// Update is called once per frame
void Update()
{
}
}
- Quay lại Unity - Play xem trong Console
0 nhận xét:
Đăng nhận xét
Thank you!