「Unity/Csharp/オブジェクト操作」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→オブジェクト検索) |
(→クリックしたオブジェクト名取得(2D版)) |
||
| 行13: | 行13: | ||
==クリックしたオブジェクト名取得(2D版)== | ==クリックしたオブジェクト名取得(2D版)== | ||
| + | カメラオブジェクトに設置 | ||
void Update () { | void Update () { | ||
if (Input.GetMouseButtonDown(0)) { | if (Input.GetMouseButtonDown(0)) { | ||
2017年9月22日 (金) 01:09時点における版
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;
Vector3 pos = obj.transform.position;
オブジェクト非表示
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);
}
}
}
