์ ๋ํฐ ์ฝ๋ฆฌ์์์ ๋ฃจ๋น ๊ฒ์ ๊ฐ์กฐํด์ ๋ง๋ค์ด๋ณด๊ณ ์๋๋ฐ. ๊ฐ์ข์ ํฌ๊ฒ ๋ค๋ฅธ ๋ถ๋ถ ์๋ ํจ์์์ CS0120์ด๋ ์ค๋ฅ๊ฐ ๋ ...
๋ญ๊ฐ ๋ฌธ์ ๊ณ ์ด๋ป๊ฒ ํด๊ฒฐํ๋ฉด ์ข์์ง ๋ชจ๋ฅด๊ฒ ๋ค ๋์์ฃผ์ธ์ ์ ๋ฐ ใ ใ
๋ณด๊ธฐ ํธํ๋ผ๊ณ ์ด๋ค ์ฝ๋๊ฐ ์ค๋ฅ์ธ์ง ๋ณผ๋์ฒด์ ๊ธ์ ํฌ์ธํธ ์ฌ๋ ธ์ด ๋์์ค์ ์ ๋ฐ ใ
๋ฐ๋ผํ๋ ๊ฐ์ข์ ์ฃผ์.
https://learn.unity.com/tutorial/weoldeu-inteoraegsyeon-tusamul?uv=2020.3&projectId=5dcdc49dedbc2a00206ce6b0#
-------------------------------------------------------์ด๊ฒ ์ค๋ฅ๊ฐ ๋๋ ์ฝ๋-------------
public class PlayerController : MonoBehaviour
{
float speed = 15.0f;
Vector2 direction = new Vector2(1, 0);
Rigidbody2D rigidbody2d;
Animator ani;
public GameObject thorwn;
void Start()
{
rigidbody2d = GetComponent<Rigidbody2D>();
ani = GetComponent<Animator>();
}
void Update()
{
float vertical = Input.GetAxis("Vertical");
Vector2 move = new Vector2(0, vertical);
ani.SetFloat("Look X", direction.x);
ani.SetFloat("Speed", move.magnitude);
Vector2 position = rigidbody2d.position;
position = position + speed * move * Time.deltaTime;
rigidbody2d.MovePosition(position);
if(Input.GetKeyDown(KeyCode.C))
{
Launch();
}
}
void Launch()
{
GameObject bulletObject = Instantiate(thorwn, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
Bullet bullet = bulletObject.GetComponent<Bullet>();
Bullet.Launch(direction, 300); //์ด๋์ด ๋ฌธ์ ... CS0120 ์ค๋ฅ๋ฅผ ๋ฑ๋๋ค..ใ ใ
ani.SetTrigger("Launch");
}
}
------------------------------------------------------------------------------
--------------------------------------------ํธ์ถํ๋ ํจ์๊ฐ ์๋ ์คํฌ๋ฆฝํธ ์ฌ๊ธฐ๋ ๋ฌธ์ ์์ -----------------------
public class Bullet : MonoBehaviour
{
Rigidbody2D rigidbody2d;
void Awake()
{
rigidbody2d = GetComponent<Rigidbody2D>();
}
public void Launch(Vector2 direction, float force)
{
rigidbody2d.AddForce(direction * force);
}
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Bullet Collision with " + other.gameObject);
Destroy(gameObject);
}
}
ํด๋น ๋๊ธ์ ์ญ์ ๋์์ต๋๋ค.
์ฐพ์๋ดค์๋๋ฐ ์ ํํ ๋ชจ๋ฅด๊ฒ ์ด์ ๊ธ์ด๊ฑฐ ์์. ๊ฐ์ฌํจ๋ค
์ด๋ฐ์ ๋ค๋ ๊ฐ๋ฐํ๊ฒ ๋ค๊ณ ...
์ฒจ๋ถํฐ ์ํ๋๋ด? ์ ์ด ๋ฐฐ์ฐ๋ ค๊ณ ํ๋๊ฑด๋ฐ ๋ญ ๊ฐ๋ ์๊ฒ ๊ธ์? ์ฌ์ฑ์ด ์์ ์ด ์๋๊ฐ?
B -> b๋ก ์์ ํ์
์....
์ ..๋์๋ฌธ์ ๊ฐ์ฌํฉ๋๋ค ใ ใ