0a94f666b7826af423ef8ef8448464b1cb8bfb0d0bc6ec2049d6b8bc8a1f885cf48ae33dc510b639a8511374

์ง€๊ธˆ ์›€์ง์ž„ ์ž์ฒด๋Š” ์—„์ฒญ ๋งŒ์กฑ์Šค๋Ÿฌ์šด๋ฐ, ํ‚ค๋ณด๋“œ๋ฅผ ๋–ผ๋ฉด ๋ฐ”๋กœ ๋ฉˆ์ถฐ๋ฒ„๋ฆฌ๋Š”๊ฒŒ ์ข€ ๊ทธ๋Ÿผ.

๋ฉˆ์ถœ๋•Œ ํฌ๊ฒŒ๋Š” ์•„๋‹ˆ๋”๋ผ๋„ ์•ฝ๊ฐ„๋งŒ ๋ฐ€๋ฆฌ๋ฉด์„œ ๋ฉˆ์ถ”๋ฉด ์ฐธ ์ด์ ๊ฑฐ๊ฐ™๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์–ด์„œ ์•„์‰ฌ์›€.

์›€์ง์ž„ ์ „์ฒด์— ๊ด€์„ฑ์„ ๋„ฃ๊ธฐ ๋ณด๋‹ค๋Š” ๋ฉˆ์ถœ ๋•Œ์—๋งŒ ๋ฐ€๋ฆฌ๊ฒŒ ๋งŒ๋“ค๊ณ  ์‹ถ์Œ

์ฐพ์•„๋ณด๋‹ˆ๊นŒ AddForce๋ผ๋Š” ๊ฑธ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค๋Š”๋ฐ, ์ด๊ฑธ ์ด์šฉํ•ด์„œ 8๋ฐฉํ–ฅ์œผ๋กœ ์›€์ง์ด๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Œ?


ํ˜„์žฌ ์ฝ”๋“œ๋Š” ์•„๋ž˜์— ์ฒจ๋ถ€ํ•จ


using System.Collections; using System.Collections.Generic; using UnityEngine; public class SCR_Submarine_Movement : MonoBehaviour { public int speed; private Rigidbody2D rigidBody; private Animator animator; private Vector2 vector; // Start is called before the first frame update void Start() { rigidBody = GetComponent<Rigidbody2D>(); animator = GetComponentInChildren<Animator>(); } // Update is called once per frame void Update() { vector.x = Input.GetAxisRaw("Horizontal"); vector.y = Input.GetAxisRaw("Vertical"); rigidBody.velocity = vector.normalized * speed; if (vector.y < 0) { animator.SetInteger("VerticalDirection", -1); } else if (vector.y > 0) { animator.SetInteger("VerticalDirection", 1); } else if (vector.y == 0) { animator.SetInteger("VerticalDirection", 0); } } }