->Distroy(this.gameObjec//소스에서 자기 자신을 죽이는 명령어
->총알같이 미리 만들어줘야하는걸 prefab이라 함
->하이러키에서 오브젝트로 들고오면 하이러키글자가 파란색으로 바뀌면서 원본이 오브젝트뷰에잇느거임
->스폰포인트라고 발사되는 지점에 작은큐브를생성
->글로벌, 로컬 (회전, 축, 좌표등 다 신경써서해야 제대로 날아감)
->
using UnityEngine; using System.Collections; public class csSpPoint : MonoBehaviour { public GameObject bullet; // Use this for initialization void Start () { Instantiate(bullet,transform.position,transform.rotation); } // Update is called once per frame void Update () { if(Input.GetButtonDown ("Fire1"))//left mouse button { Instantiate(bullet,transform.position,transform.rotation); } } }
Input.GetKeyDown는 파라미터가 KeyCode, string 을통해서 일반적인 키보드 입력을
받는거고요.
Input.getButtonDown 에는 KeyCode가 아니라 buttonName으로 작동하는데요.
buttonName은 Edit->Project Settings->Input 클릭해보시면 세팅할 수 있어요. >
->적같은경우는 prefab으로 하되, 이름보다는 태그로 구분
->
using UnityEngine; using System.Collections; public class csBullet : MonoBehaviour { public GameObject exp; // Use this for initialization void Start () { } void OnTriggerEnter(Collider obj) { if(obj.tag=="enemy") { Destroy (obj.gameObject); } Instantiate(exp,transform.position,transform.rotation); Destroy(this.gameObject); } // Update is called once per frame void Update () { float speed = 12.0f; transform.Translate(Vector3.forward*speed*Time.deltaTime); } }
'Unity' 카테고리의 다른 글
Unity3D #8 (0) | 2015.01.14 |
---|---|
Unity3D #7 (0) | 2015.01.13 |
Unity3D #5 (0) | 2015.01.09 |
Unity3D #4 (0) | 2015.01.08 |
Unity3D #3 (0) | 2015.01.07 |