The script was created with legacy Input Manager. It can simply get your mouse state when it is on edge of the screen. The “GetMouseEdgeState” method can return Top, Down, Left, Right, Top Left, Top Right, Down Left, and Down Right state. It also returns an unknown state when the mouse is over the game window.
二、在 Rig1 下建立一個空物件,先給他新增一個「Two Bone IK Constraint」,再將模型骨架中的手部物件拖入 Tip 欄位,最後在組件的標題上滑鼠右鍵選單執行 Auto Setup from Tip Transform,其他的組件欄位將會自動設置完畢,也會多出 target 和 hint 兩個子物件。
var x = center.x + radius * Mathf.Cos(rad);
var y = center.y + radius * Mathf.Sin(rad);
四、最後加入物件生成後會像這樣,指定於角度 20 度座標位置生成一個 Ball 物件:
public GameObject Ball;
private void Start()
{
var center = new Vector3(0, 0, 0);
var radius = 3;
var rad = 20 * Mathf.PI / 180;
var x = center.x + radius * Mathf.Cos(rad);
var y = center.y + radius * Mathf.Sin(rad);
Ball.transform.position = new Vector3(x, y, center.z);
Instantiate(Ball);
}
Unity 預覽,紅點為圓心,白點為生成的 Ball。
五、實際運用方面,我們可以用迴圈達成「在圓周上每 20 度生成一個物件」的目的。
public GameObject Ball;
private void Start()
{
var center = new Vector3(0, 0, 0);
var radius = 3;
for (int i = 0; i < 360; i += 20)
{
var rad = i * Mathf.PI / 180;
var x = center.x + radius * Mathf.Cos(rad);
var y = center.y + radius * Mathf.Sin(rad);
Ball.transform.position = new Vector3(x, y, center.z);
Instantiate(Ball);
}
}
if (_contentSizeFitter == null) _contentSizeFitter = GetComponentsInChildren<ContentSizeFitter>();
foreach (var e in _contentSizeFitter)
{
LayoutRebuilder.ForceRebuildLayoutImmediate(e.GetComponent<RectTransform>());
}
var cubes = new List<GameObject>();
var asyncWork = Addressables.LoadAssetsAsync<GameObject>("Cube", cubes.Add);
await asyncWork.Task;
foreach (var e in cubes)
{
Debug.Log(e.name);
}
public AssetReference allType;
public AssetReferenceGameObject gameObj;
public AssetReferenceTexture texture;
public AssetReferenceT<TextAsset> textAsset;
範例 (Async 寫法):
await gameObj.LoadAssetAsync<GameObject>().Task;
gameObj.InstantiateAsync().Completed += x => {
x.Result.AddComponent<BoxCollider>();
};