IT는 개발자

unity 화살 생성하기 본문

unity

unity 화살 생성하기

뚜둔64 2019. 11. 19. 13:44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class ArrowGenerator:MonoBehaviour{
    public GameObject arrowPrefab;
    float span = 1.0f;        //화살의 생성 간격을 바꿀 수 있다 (0.5가 되면 두배)
    float delta = 0;
 
    void Update(){
        this.delta += Time.deltaTime;        //지난 프레임이 완료되는 데 까지 걸린 시간
        if(this.delta > this.span){
            this.delta = 0;
            GameObject go = Instantiate(arrowPrefab) as GameObject;        //Instantiate: 오브젝트의 인스턴스 ID를 반환
            int px = Random.Range(-67);                                //-6~7사이의 랜덤 수 반환
            go.transform.position = new Vector3(px, 70);                //월드 공간에서 트랜스폼의 위치
        }
    }
}
 
//화살을 계속 생성해내는 스크립트!
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

 

'unity' 카테고리의 다른 글

unity 이벤트 함수  (0) 2020.01.20
unity canvas 사이즈 조정  (0) 2020.01.20
unity 기본 개념 정리  (0) 2020.01.16
unity 싱글톤을 활용한 코드 작성하기  (0) 2019.11.19
unity 이미지 게이지 관련 바(에너지 채우기)  (0) 2019.11.19
Comments