์ข ์ผ๋ก ๋๊ฐ๋๊ฑฐ ํก์ผ๋ก ๋ฐ๊พธ๊ณ ์ถ์ด.
์๋ C# ์ข๋ ๋ชจ๋ฅด๊ณ ํ์ด์ฌ์ด๋ ๊น๋ฑ๊ฑฐ๋ฆฐ ๊ฐ๊ฒ๋ก
์ฝ๋๋๋ณต๋ถ... ๊ทผ๋ฐ C# ์๊ณ ์์ด๋ ์ ๊ฑฐ 100% ์ดํดํ ๊ฑฐ ๊ฐ์ง๋ ์๋ค.
์ผ๋ฐ์ ์ธ C#ํ๊ณ ์ ๋ํฐ C#ํ๊ณ ์ ๋ฒ ๋ค๋ฅผํฐ์ด๋.
์บ๋ฆญํฐ ์ฝ๋๊ฐ ๋์ถฉ ์ด๋ชจ์์ด๊ณ
using UnityEngine;
using System.Collections;
public class girl_robot : MonoBehaviour {
public GameObject explosionPrefab;
public const float moveSpeed = 15.0f;//์์ง์ด๋ ์๋๋ฅผ ์ ์ํด ์ค๋๋ค.
public GameObject laserPrefab; //๋ฐ์ฌํ ๋ ์ด์ ๋ฅผ ์ ์ฅํฉ๋๋ค.
public bool canShoot = true; //๋ ์ด์ ๋ฅผ ์ ์ ์๋ ์ํ์ธ์ง ๊ฒ์ฌํฉ๋๋ค.
const float shootDelay = 0.5f; //๋ ์ด์ ๋ฅผ ์๋ ์ฃผ๊ธฐ๋ฅผ ์ ํด์ค๋๋ค.
float shootTimer = 0; //์๊ฐ์ ์ด ํ์ด๋จธ๋ฅผ ๋ง๋ค์ด์ค๋๋ค.
void Start () {
}
void Update () {
moveControl();
ShootControl();
//์บ๋ฆญํฐ๋ฅผ ์์ง์ด๋ ํจ์๋ฅผ ํ๋ ์๋ง๋ค ํธ์ถ ํฉ๋๋ค.
}
void moveControl ()
{
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate (Vector3.left * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate (Vector3.right * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate (Vector3.up * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate (Vector3.down * moveSpeed * Time.deltaTime);
}
}
void ShootControl() // ๋ฐ์ฌ๋ฅผ ๊ด๋ฆฌํ๋ ํจ์ ์ ๋๋ค.
{
if (canShoot) // ์ ์ ์๋ ์ํ์ธ์ง ๊ฒ์ฌํฉ๋๋ค.
{
if (shootTimer > shootDelay && Input.GetKey(KeyCode.Space)) //์ฟจํ์์ด ์ง๋ฌ๋์ง์, ๊ณต๊ฒฉํค์ธ ์คํ์ด์ค๊ฐ ๋๋ ค์๋์ง ๊ฒ์ฌํฉ๋๋ค.
{
Instantiate(laserPrefab, transform.position, Quaternion.identity); //๋ ์ด์ ๋ฅผ ์์ฑํด์ค๋๋ค.
shootTimer = 0; //์ฟจํ์์ ๋ค์ ์นด์ดํธ ํฉ๋๋ค.
}
shootTimer += Time.deltaTime; //์ฟจํ์์ ์นด์ดํธ ํฉ๋๋ค.
}
}
void OnTriggerEnter2D(Collider2D other)
//rigidBody๊ฐ ๋ฌด์ธ๊ฐ์ ์ถฉ๋ํ ๋ ํธ์ถ๋๋ ํจ์ ์ ๋๋ค.
//Collider2D other๋ก ๋ถ๋ชํ ๊ฐ์ฒด๋ฅผ ๋ฐ์์ต๋๋ค.
{
if (other.gameObject.tag.Equals("enemy"))
//๋ถ๋ชํ ๊ฐ์ฒด์ ํ๊ทธ๋ฅผ ๋น๊ตํด์ ์ ์ธ์ง ํ๋จํฉ๋๋ค.
{
/* ์ฌ๊ธฐ์ ๋ถํฐ ์ถ๊ฐ๋ ๋ถ๋ถ*/
Instantiate(explosionPrefab,
// Instantiate๋ ๊ฐ์ฒด๋ฅผ ํ๋ ์์ฑ(๋ณต์ )ํฉ๋๋ค ์ฒซ๋ฒ์งธ ์ธ์๋ก๋ ์์ฑํ ๊ฐ์ฒด์ ์๋ณธ์ ๋ฃ์ด์ฃผ๊ณ
this.transform.position,
//๋๋ฒ์งธ ์ธ์๋ก๋ ์์ฑ๋ ์์น๋ฅผ ๋ฃ์ด์ค๋๋ค. this.transform.position์ ์๊ธฐ์์ ์ ์์น๋ฅผ ๋ํ๋ ๋๋ค.
Quaternion.identity);
//์ธ๋ฒ์งธ ์ธ์๋ก๋ ๊ฐ์ฒด์ ํ์ ๊ฐ์ ๋ฃ์ด์ฃผ๋๋ฐ์, Quaternion.identity๋ ํ์ ์ด ์ ์ฉ๋์ง ์์ ๊ฐ์ ๋ํ๋ ๋๋ค.
/* ์ฌ๊ธฐ๊น์ง */
Destroy(other.gameObject);
//์ ์ ํ๊ดดํฉ๋๋ค.
Destroy(this.gameObject);
//์์ ์ ํ๊ดดํฉ๋๋ค.
}
}
}
laser์์ transform.Translate(0, moveY, 0);๋ฅผ ( moveY, 0,0)๋ก ๋ฐ๊ฟ๋ณด์ ์๋๋ฉด (0,0, moveY)๋
๊ทธ๋ํฝ ์ด์๋ค ์ง์ ๋ง๋์ ๊ฑฐ?
ใด ๋น์ฐํ ์๋์ ธ
ํ๋ฆฌํ ์ ํด๋ ์ด์์ด ์๋ฅผ ์ณ๋ค๋ณด๋๊น ์๋ก ๋๊ฐ์ง ๊ทธ๋ฆฌ๊ณ ์ฒซ๋ ๋ง๋๋ก X์ถ์ผ๋ก ์ด๋ํ๊ฒ ์์ ๋ฐ๊ฟ
ใ ใ ๋ ๊ฐ์ฌํฉ๋๋ค ์ค๋์ ์ด๋ง ์๊ณ ๋ด์ผ ํด๋ณผ๊ฒ์
ใ ใ ๋๋ ๊ฐ์ฌํฉ๋๋ค ๊พธ๋ฒ
์ด ํ๋ฆฌํน์ ๋ํ์๋ ํด๋ดค๋๋ฐ ๋ํ์ฒด๋ก ์๋ก ๋๊ฐ๋๊ตฐ์....
์ง๊ธ ์ ์ด์ ๋ ์ด์ ์์ฒด๊ฐ ์๋ก๋๊ฐ๊ฒ ์ฝ๋๊ฐ๋์๋ค
๊ณ ๋ง์ ใ ใ ํ ํด๊ฒฐํ์ด ใณใณ