์œ ๋‹ˆํ‹ฐ ์ฝ”๋ฆฌ์•„์—์„œ ๋ฃจ๋น„ ๊ฒŒ์ž„ ๊ฐœ์กฐํ•ด์„œ ๋งŒ๋“ค์–ด๋ณด๊ณ  ์žˆ๋Š”๋ฐ. ๊ฐ•์ขŒ์™€ ํฌ๊ฒŒ ๋‹ค๋ฅธ ๋ถ€๋ถ„ ์—†๋Š” ํ•จ์ˆ˜์—์„œ 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);

}

}