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);

}

}


์ผ๋‹จ ๋Œ€์ถฉ ์ด๋ ‡๊ฒŒ ํ•˜๊ณ 

ํŠœํ† ๋ฆฌ์–ผ๋ณด๋ฉด์„œ ๊ธฐ์ดˆ๋ž‘ย ๋””๋ฒ„๊ทธํ•˜๋Š” ๋ฐฉ๋ฒ•๋ถ€ํ„ฐ ์ตํžˆ์ž%