Vector2Int coordinates; //λ³μ μ μΈ
Update()
{
coordinates.x = (int) transform.parent.position.x;Β
coordinates.x = Mathf.RoundToInt(transform.parent.position.x);
}
κ°μμμλ μ λ°μ΄νΈμ λ€μ΄κ° λ μ½λ μ€ μλμ μ½λλ₯Ό μ¬μ©νλκ΅°μ.
C# μ± κ³΅λΆ μ€μ μ¬λͺ μμ μ½λλ λ μ¬λΌ μ μ΄ λ³΄μλλ°
μ΄ λ κ°μ§λ μ΄λ€ μ°¨μ΄κ° μλμ?
첫λ²μ§Έλ 10.9λ₯Ό 10μ΄λΌνλλ° λλ²μ§ΈκΊΌλ 11μ΄λΌ νμ§μλ?
μμ κ±°λ... κ°μ νλ³νμ΄κ³ κ°μ λ³νμ μκΈ°κ° λ΄μ μ μλ λ²μ κ°λ§ λ΄μ μ μμ int νμ΄λκΉ μμμ μ λ€ λ²λ¦¬κ³ μ μλ§ λ°λκ±°μ§. μλ κ±°λ math ν΄λΌμ€μ λ©μλλ₯Ό μ¬μ©ν건λ°RoundToInt() λ©μλλ 첫 λ²μ§Έ μμμ μ λ°μ¬λ¦Ό νλ λ©μλμ.
https://www.dotnetperls.com/cast-int
λ§μ½ transform.parent.position.xμ κ°μ΄ 10.9f μ΄λΌκ³ μΉλ©΄ (int) transform.parent.position.x κ°μ 10 μ΄λκ³ Mathf.RoundToInt(transform.parent.position.x) κ°μ 11μ΄ λλ€. Mathf.RoundToInt λ©μλλ 첫 λ²μ§Έ μμμ μ λ°μ¬λ¦Όνκ³ intνμΌλ‘ λ°κΎΈλ λ©μλμΌ
λ΅λ³ κ°μ¬ν©λλ€!
μλ λ²λ¦Ό μλλ λ°μ¬λ¦Ό