Unity 小技巧
*Rename(重新命名) Unity Project
- Change the unity project folder name (the parent folder of 'Assets' folder)
- Remove any file with .sln or .csproj suffixes under the project folder(A sibling of Asset folders). (Unity will regenerate them)
*Double click Canvas in hierarchy
=> UI Text 放置的地方Text 在 Canvas 的相對位置 就是,Text 在 Camera (螢幕)的位置
*出現警告 :
There are inconsistent line endings in the 'Assets/Script/Button0.cs' script. Some are Mac OS X (UNIX) and some are Windows.This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
在Visual Studio => 工具 -> 選項 -> 文字編輯器 -> 自動偵測無簽章的 UTF-8 編碼 => 勾選
*Button 加入 函式
1.Create a Button in Hierarchy.2.Add a script(button0.cs) to the Button.
3.-----------------------button0.cs -------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Button0 : MonoBehaviour
{
public void onBtn()
{
Debug.Log("Button has clicked.");
}
}
--------------------------------------------------------------
4. 將 Button 物件 從 Hierarchy 拖曳到 Button->Button(Script)->onClick 中
5.選擇 Button0.onBtn 函式
4. 將 Button 物件 從 Hierarchy 拖曳到 Button->Button(Script)->onClick 中
5.選擇 Button0.onBtn 函式
Unity Script
*常用類型
public Button btn;//UnityEngine.UI
public Text text; // UnityEngine.UI
public GameObject GO;
*將 child object 加入 parent object
public Button btn;//UnityEngine.UI
public Text text; // UnityEngine.UI
public GameObject GO;
*將 child object 加入 parent object
public GameObject BackGround;//BackGround 是 parent
public GameObject temp; // temp 是 child
temp = Instantiate(square[(k+i) % 2], new Vector3(x,y, 0), Quaternion.identity);
temp.transform.parent = BackGround.transform;
*
int i = (int) Mathf.Round(someFloat);
*
Input.GetKeyDown(KeyCode.LeftArrow)
Input.GetKeyDown(KeyCode.RightArrow)
Input.GetKeyDown(KeyCode.UpArrow)
Input.GetKeyDown(KeyCode.DownArrow)
* 隨機 產生 0~Max-1 的數
int i = Random.Range(0, Max);
*刪除物件
Destory(gameObject);
*縮放
<GameObject>.transform.localScale = new Vector3(2,2,2);
*換場景
temp.transform.parent = BackGround.transform;
*
int i = (int) Mathf.Round(someFloat);
*
Input.GetKeyDown(KeyCode.LeftArrow)
Input.GetKeyDown(KeyCode.RightArrow)
Input.GetKeyDown(KeyCode.UpArrow)
Input.GetKeyDown(KeyCode.DownArrow)
* 隨機 產生 0~Max-1 的數
int i = Random.Range(0, Max);
*刪除物件
Destory(gameObject);
*縮放
<GameObject>.transform.localScale = new Vector3(2,2,2);
*換場景
using UnityEngine.SceneManagement;
SceneManager.LoadScene("場景名稱");
留言
張貼留言