「Unity/Csharp/オブジェクト操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→クリックしたオブジェクト名取得) |
(→x方向に移動) |
||
| 行1: | 行1: | ||
==x方向に移動== | ==x方向に移動== | ||
void Update () { | void Update () { | ||
| − | Vector3 | + | Vector3 pos = transform.position; |
| − | transform.position = new Vector3( | + | transform.position = new Vector3(pos.x + 0.01f, pos.y, pos.z); |
} | } | ||
| + | |||
| + | ==オブジェクト検索== | ||
| + | GameObject obj = transform.Find("block_8").gameObject; | ||
| + | |||
| + | ==オブジェクト非表示== | ||
| + | obj.SetActive (false); | ||
==クリックしたオブジェクト名取得(2D版)== | ==クリックしたオブジェクト名取得(2D版)== | ||
2017年9月16日 (土) 09:15時点における版
x方向に移動
void Update () {
Vector3 pos = transform.position;
transform.position = new Vector3(pos.x + 0.01f, pos.y, pos.z);
}
オブジェクト検索
GameObject obj = transform.Find("block_8").gameObject;
オブジェクト非表示
obj.SetActive (false);
クリックしたオブジェクト名取得(2D版)
void Update () {
if (Input.GetMouseButtonDown(0)) {
Vector2 tap = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Collider2D collition = Physics2D.OverlapPoint(tap);
if (collition) {
Debug.Log (collition.transform.gameObject.name);
}
}
}
