직선공격
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boss : MonoBehaviour
{
//총알 프리팹
public GameObject EnemyBullet2Prefab;
//총알 발사 시간
float delta;
void Update()
{
this.Attack01();
}
private void Attack01()
{
//총알 발사 간격
float span = 1.0f;
//원형 총알 발사
this.delta += Time.deltaTime;
if (this.delta > span)
{
GameObject bulletR = Instantiate(EnemyBullet2Prefab) as GameObject;
bulletR.transform.position = new Vector3(this.transform.position.x - 0.84f, this.transform.position.y - 0.8f, 0);
GameObject bulletRR = Instantiate(EnemyBullet2Prefab) as GameObject;
bulletRR.transform.position = new Vector3(this.transform.position.x - 0.63f, this.transform.position.y - 0.8f, 0);
GameObject bulletL = Instantiate(EnemyBullet2Prefab) as GameObject;
bulletL.transform.position = new Vector3(this.transform.position.x + 0.84f, this.transform.position.y - 0.8f, 0);
GameObject bulletLL = Instantiate(EnemyBullet2Prefab) as GameObject;
bulletLL.transform.position = new Vector3(this.transform.position.x + 0.63f, this.transform.position.y - 0.8f, 0);
//발사했다면 쿨타임 초기화
this.delta = 0;
}
}
}
원형공격
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Boss : MonoBehaviour
{
//총알 프리팹
public GameObject EnemyBullet0Prefab;
//총알 발사 시간
float delta;
//총알 발사 간격
public float span;
//총알 각도 변경용
public int bulletSwitch;
void Update()
{
//원형 총알 발사
this.delta += Time.deltaTime;
if (this.delta > this.span)
{
switch (bulletSwitch)
{
case 0:
for (int i = 0; i < 40; i++)
{
GameObject bullet0 = Instantiate(EnemyBullet0Prefab) as GameObject;
bullet0.transform.position = this.transform.position;
bullet0.transform.rotation = Quaternion.Euler(0, 0, (i + 1) * 9);
this.bulletSwitch = 1;
}
break;
case 1:
for (int i = 0; i < 40; i++)
{
GameObject bullet0 = Instantiate(EnemyBullet0Prefab) as GameObject;
bullet0.transform.position = this.transform.position;
bullet0.transform.rotation = Quaternion.Euler(0, 0, (i + 1) * 9 + 4.5f);
this.bulletSwitch = 0;
}
break;
}
//발사했다면 쿨타임 초기화
this.delta = 0;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBullet0 : MonoBehaviour
{
void Start()
{
}
void Update()
{
this.transform.Translate(this.transform.up * 1 * Time.deltaTime, Space.World);
//화면을 벗어나면 파괴
if (this.transform.position.x < -9 || this.transform.position.x > 9 || this.transform.position.y < -5.5f || this.transform.position.y > 5.5f)
{
Destroy(this.gameObject);
}
}
}
'Unity > 게임 엔진 응용 프로그래밍' 카테고리의 다른 글
| 유니티 Resources 폴더 (0) | 2021.10.18 |
|---|---|
| [Unity 3D] MiniRPG : 게임 기획하기 (0) | 2021.10.18 |
| Vertical 2D Shooting 10 : 적기 총알발사 (0) | 2021.10.15 |
| Vertical 2D Shooting 09 : 코루틴으로 무적시간 구현 (0) | 2021.10.15 |
| Vertical 2D Shooting 08 : 코인 이이템 드롭 (0) | 2021.10.15 |