π Unity Transform Position
- μ λν° Vector3λ μ€νμ μμ±λλ€, κ° νμμ΄λ€, Struct
- μ λν° Vector3 Struct
- C# new Struct
http://smilejsu.tistory.com/560
https://velog.io/@csm2652/C-Struct%EC%97%90%EC%84%9C%EC%9D%98-NEW-%ED%82%A4%EC%9B%8C%EB%93%9C
https://answers.unity.com/questions/225729/gameobject-positionset-not-working.html
https://forum.unity.com/threads/vector3-and-other-structs-optimization-of-operators.477338/
https://answers.unity.com/questions/1033383/code-performance-when-to-use-new-on-vector3.html
λ€λ£¨λ μ£Όμ
- transform.position = new Vector3(n, n, n);
- λ°λ³΅μ μΈ βnewβ Vector3 λ νΌν¬λ¨Όμ€μ μν₯μ μ£Όμ§ μλκ°?
- μ transform.position.Set() μ μλλλ‘ μλνμ§ μλκ°?
- μ transform.position = new Vector3(n, n, n); μ μλλλ‘ μλνλκ°?
- transform.position λ μ΄λ»κ² λμκ°λ κ±ΈκΉ? (λνΌμ )
- transform.position.x λ μ readonly μΈκ°?
λ°λ³΅μ μΈ βnewβ Vector3 λ νΌλͺ¨λ¨Όμ€μ μν₯μ μ£Όμ§ μλκ°?
Vector3λ Classκ° μλλΌ Struct.
C#μμ Struct μμ± μ new λ₯Ό μ¬μ©νλ κ²μ, λ¨μν ꡬ쑰체λ₯Ό μ΄κΈ°ννλ λ°©λ² μ€ νλ
μ€νμ λ¨μν Value κ° μμ± νκ΄΄νλ κ²μ΄κΈ° λλ¬Έμ,
νμ ν΄λμ€ μμ± νκ΄΄ν λμ²λΌ κ°λΉμ§κ° μκΈ°μ§ μμ
μ°Έκ³ : λ¬Όλ‘ Struct μμ±μλ κ³μ νΈμΆλκ³ μμ !
μ transform.position.Set() μ μλλλ‘ μλνμ§ μλκ°?
μ transform.position = new Vector3(n, n, n); μ μλλλ‘ μλνλκ°?
transform.position λ μ΄λ»κ² λμκ°λ κ±ΈκΉ? (μ μΆ)
transform.position.Set() μ μλλλ‘ μλνμ§ μλλ€.
κ·Όλ° λ transform.position = new Vector3(n, n, n); λ μλλλ‘ μλνλ€.
μ΄κ±΄ μ²μ μ λν°λ₯Ό λ€λ£° λ κ²ͺκ²λλ κ²½νκ³Ό μ¬μ€
transform.positionμ νλ‘νΌν°μΈκ² μλκΉ?
1
2
3
4
5
6
7
8
private Vector3 realPosition;
public Vector3 position
{
get => realPosition;
set => realPosition = value;
}
Vector3λ μμμ μΈκΈνλ― Struct
transform.position μμ Vector3, Struct μ΄λ―λ‘,
transform.positionμΌλ‘ Getν Vector3λ, transform λ΄λΆμμ μλνλ μ€μ positionμ΄ μλλΌ,
μ€μ positionκ³Ό κ°μ΄ λκ°μ, μ€μ positionμ 볡μ¬λ³Έ Vector3μ΄ λ¦¬ν΄λλ κ²
λλ¬Έμ 볡μ λμ΄ returnλ Vector3λ₯Ό μ무리 Set() ν΄λ, μ€μ transform.positionμ μν₯μ μ£Όμ§ μμ.
λ°λλ‘ λμ
μ°μ°μλ‘ νλ‘νΌν°μ μ§μ μ μΌλ‘ Set ν λλ,
λκ²¨μ€ Vector3κ° νλ‘νΌν°κ° κ°λ¦¬ν€λ μ€μ ν¬μ§μ
κ°μ λμ
νκΈ° λλ¬Έμ μλλλ‘ μλνμ§ μμκΉ μΆμ !
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
private Vector3 realPosition;
public Vector3 position
{
get
{
return μλ μ’νκ³ κΈ°μ€ position;
}
set
{
realPosition = λ‘컬 μ’νκ³ κΈ°μ€ value;
μ€λΈμ νΈ μμΉ μ²λ¦¬();
}
}
λ¬Όλ‘ !
μ€μ λ‘ λ΄λΆ μ²λ¦¬κ° μ΄λ€μ§ μ λͺ¨λ₯΄κ² μ§λ§,
μμ²λΌ κ°μ μΌλ ¨μ μ²λ¦¬κ³Όμ μ΄ λ 볡μ‘νκ² μμ§ μμκΉ μΆλ€
transform.position.x λ μ readonly μΈκ°?
transform.positionμ Vector3, Struct
transform.positionμΌλ‘ Getνμ¬ κ°μ Έμ¨ 볡μ λ Vector3λ,
μλ³Έμ΄ μλ, λ³μκ° μλ, μ¬λ 곡κ°μ΄ μλ Struct βκ°β
Structμ κ°μ κ° νμμΈ intμ λνμ¬, 100 = 0; μ΄ μλ―Έ μλ λͺ
λ ΉμΈ κ² μ²λΌ,
Structλ βκ°β μ κ°μ λμ
νλ μΌμ μλ―Έκ° μλ€
1
2
SomeStruct ss;
ss.SomeVar = 1;
μ΄κ±΄ μλ―Έκ° μλ€
ss λΌλ SomeStruct λ³μμ SomeVar κ°μ λ°κΎΈκ³ μ μ₯νλ€.
κ²°κ³Όκ° λ¨λλ€.