using UnityEngine;
public class Player : MonoBehaviour
{
public Bullet bulletPrefab;
Vector3 input;
Vector3 direction = Vector3.right;
float speed = 10f;
void Update()
{
Movement();
Fire();
}
void Movement()
{
float h = Input.GetAxisRaw("Horizontal");
input = new Vector3(h, 0, 0);
transform.Translate(input * speed * Time.deltaTime);
if (input != Vector3.zero)
direction = input;
}
void Fire()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Vector3 firePos = transform.position + direction;
Bullet bullet = Instantiate(bulletPrefab, firePos, Quaternion.identity) as Bullet;
bullet.Direction = direction;
}
}
}
//======================================================================
using UnityEngine;
public class Bullet : MonoBehaviour
{
float speed = 20f;
Vector3 direction;
public Vector3 Direction
{
set { direction = value; }
}
void Update()
{
transform.Translate(direction * speed * Time.deltaTime);
}
}
์ผ๋จ ๋์ถฉ ์ด๋ ๊ฒ ํ๊ณ
ํํ ๋ฆฌ์ผ๋ณด๋ฉด์ ๊ธฐ์ด๋ย ๋๋ฒ๊ทธํ๋ ๋ฐฉ๋ฒ๋ถํฐ ์ตํ์%
๊ณ ๋ง์์.. ๋ญ๊ฐ ํญ์ ๋ฌด์์ํ ๋ ํํ ๋ฆฌ์ผ ๋ณด๊ณ ๊ตญ์ด์ฑ ์ฝ๋ฏ ๋ฐ๋ผํ๊ณ .. ํ๋ผ๋๋๋ก ํ๋ค๋ณด๋ ์ฌ๋ฏธ๋ ์๋ถ๊ณ ์๋๋ ์๋์ ๋ถ๋ซํ๋ ํ์์ผ๋ก ํ๋ค๋ณด๋ ์ด๋ ๊ฒ ๋๋ค์ ๊ฐ์ฌํฉ๋๋ค - dc App