hp가 0일때 화살을 더이상 만들지 않기
1. 레바를 만들어서 hp가 0이면 공장작동중지시키기
GameDirector
public void DecreaseHp()
{
Image image = this.hpGauge.GetComponent<Image>();
image.fillAmount -= 0.1f;
if (image.fillAmount == 0)
{
GameObject arrowGeneratorGo = GameObject.Find("ArrowGenerator");
ArrowGenerator arrowGenerator = arrowGeneratorGo.GetComponent<ArrowGenerator>();
arrowGenerator.isAllive = false;
}
}
ArrowGenerator 화살공장
public GameObject arrowPrefab;
float span = 1.0f;
float delta = 0;
public bool isAllive = true;
// Update is called once per frame
void Update()
{
this.delta += Time.deltaTime; //매 프레임마다 경과시간을 누적
if (this.delta > this.span && isAllive) //1초보다 넘어갔고 살아있다면
{
//누적시간 초기화
this.delta = 0;
//프리팹의 인스턴스를 생성한다
GameObject go = Instantiate(this.arrowPrefab) as GameObject;
int px = Random.Range(-6, 7); //-6 ~ 6사이 x좌표
go.transform.position = new Vector3(px, 7, 0);
}
}
2. hp가 0이면 아예 공장을 파괴시켜버리기
캐릭터를 움직일때 화면밖으로 나가지 않도록하기
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
this.transform.Translate(-3, 0, 0);
if (this.transform.position.x < -8.38f)
{
this.transform.position = new Vector3(-8.38f, -3.64f, 0);
}
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
this.transform.Translate(3, 0, 0);
if (this.transform.position.x > 8.44f)
{
this.transform.position = new Vector3(8.44f, -3.64f, 0);
}
}
}
'유니티 > 수업 내용' 카테고리의 다른 글
2D슈팅 - 배경 스크롤링 (0) | 2022.01.18 |
---|---|
2D슈팅 - 적기A, B 애니메이션, 피격연출, 등장패턴추가 (0) | 2022.01.18 |
유니티 룰렛 - 마우스 클릭(입력)에 따라 동작 (0) | 2022.01.18 |
스크립터블 오브젝트 생성 툴 (0) | 2021.12.23 |
[3D RPG 프로토타입] 몬스터와 전투 이벤트기반, 가장 가까운 적 찾기 (0) | 2021.12.23 |