image1 image2 image3

HELLO I'M VIET|WELCOME TO MY PERSONAL BLOG|I LOVE TO DO CREATIVE THINGS

Unity bài 1: Tổng quan về Unity



Nội dung bài viết
  1. Trình soạn thảo script
  2. GameObject và script C#
  3. 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

Share this:

CONVERSATION

0 nhận xét:

Đăng nhận xét

Thank you!