1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCollider2DSize : MonoBehaviour
{
public GameObject m_prefab;
// Start is called before the first frame update
void Start()
{
FunctionC();
}
void FunctionA()
{
BoxCollider2D collider = GetComponent<BoxCollider2D>();
Vector2 size = collider.size;
Vector3 centerPoint = new Vector3(collider.offset.x, collider.offset.y, 0f);
Vector3 worldPos = transform.TransformPoint(collider.offset);
float top = worldPos.y + (size.y / 2f);
float btm = worldPos.y - (size.y / 2f);
float left = worldPos.x - (size.x / 2f);
float right = worldPos.x + (size.x / 2f);
Vector3 topLeft = new Vector3(left, top, worldPos.z);
Vector3 topRight = new Vector3(right, top, worldPos.z);
Vector3 btmLeft = new Vector3(left, btm, worldPos.z);
Vector3 btmRight = new Vector3(right, btm, worldPos.z);
Debug.Log(this.gameObject.name + ", topLeft : " + topLeft);
Debug.Log(this.gameObject.name + ", topRight : " + topRight);
Debug.Log(this.gameObject.name + ", btmLeft : " + btmLeft);
Debug.Log(this.gameObject.name + ", btmRight : " + btmRight);
Instantiate(m_prefab).transform.position = topLeft;
Instantiate(m_prefab).transform.position = topRight;
Instantiate(m_prefab).transform.position = btmLeft;
Instantiate(m_prefab).transform.position = btmRight;
}
void FunctionB()
{
BoxCollider2D collider = GetComponent<BoxCollider2D>();
Vector2 size = collider.size;
Vector3 centerPoint = new Vector3(collider.offset.x, collider.offset.y, 0f);
Vector3 worldPos = transform.TransformPoint(collider.offset);
Rect rect = new Rect(0f, 0f, size.x, size.y);
rect.center = new Vector2(worldPos.x, worldPos.y);
Vector3 topLeft = new Vector3(rect.xMin, rect.yMax, worldPos.z);
Vector3 topRight = new Vector3(rect.xMax, rect.yMax, worldPos.z);
Vector3 btmLeft = new Vector3(rect.xMin, rect.yMin, worldPos.z);
Vector3 btmRight = new Vector3(rect.xMax, rect.yMin, worldPos.z);
Debug.Log(this.gameObject.name + ", topLeft : " + topLeft);
Debug.Log(this.gameObject.name + ", topRight : " + topRight);
Debug.Log(this.gameObject.name + ", btmLeft : " + btmLeft);
Debug.Log(this.gameObject.name + ", btmRight : " + btmRight);
Instantiate(m_prefab).transform.position = topLeft;
Instantiate(m_prefab).transform.position = topRight;
Instantiate(m_prefab).transform.position = btmLeft;
Instantiate(m_prefab).transform.position = btmRight;
}
void FunctionC()
{
BoxCollider2D collider = (BoxCollider2D)this.gameObject.GetComponent<Collider2D>();
float top = collider.offset.y + (collider.size.y / 2f);
float btm = collider.offset.y - (collider.size.y / 2f);
float left = collider.offset.x - (collider.size.x / 2f);
float right = collider.offset.x + (collider.size.x / 2f);
Vector3 topLeft = transform.TransformPoint(new Vector3(left, top, 0f));
Vector3 topRight = transform.TransformPoint(new Vector3(right, top, 0f));
Vector3 btmLeft = transform.TransformPoint(new Vector3(left, btm, 0f));
Vector3 btmRight = transform.TransformPoint(new Vector3(right, btm, 0f));
Debug.Log(this.gameObject.name + ", topLeft : " + topLeft);
Debug.Log(this.gameObject.name + ", topRight : " + topRight);
Debug.Log(this.gameObject.name + ", btmLeft : " + btmLeft);
Debug.Log(this.gameObject.name + ", btmRight : " + btmRight);
Instantiate(m_prefab).transform.position = topLeft;
Instantiate(m_prefab).transform.position = topRight;
Instantiate(m_prefab).transform.position = btmLeft;
Instantiate(m_prefab).transform.position = btmRight;
}
}
| cs |
댓글
댓글 쓰기