1. GameObject 타입의 변수를 추가해준다. 이 변수에 추가한 Object가 생성하게 될 Object가 된다.
2. Instantiate(생성할 Object, 생성할 위치값, 생성할 회전값)으로 Object가 생성된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | public class PlayerControl : MonoBehaviour { public float speed = 15.0f; private Transform myTransform = null; // 생성하게 될 Object public GameObject BulletPrefab = null; // Start is called before the first frame update void Start() { myTransform = GetComponent<Transform>(); } // Update is called once per frame void Update() { float axis = Input.GetAxis("Horizontal"); Vector3 moveAmout = axis * speed * -Vector3.right * Time.deltaTime; myTransform.Translate(moveAmout); if(Input.GetKeyDown(KeyCode.Space) == true) { //인스턴싱. Instantiate(BulletPrefab, myTransform.position, Quaternion.identity); } } } | cs |
'유니티' 카테고리의 다른 글
[유니티] Object 충돌 (0) | 2019.03.08 |
---|---|
[유니티] Random 위치에 Object 이동 (0) | 2019.03.07 |
[유니티]Object 삭제 (0) | 2019.03.04 |
[유니티] Object 좌우 이동 (0) | 2019.03.02 |
[유니티] Object에 Script연결 (0) | 2019.03.01 |