Unity2D
Unity) [유니티 2D] 슈터게임 여러 갈래의 탄환 구현
HSH12345
2023. 4. 14. 13:05
int bulletAmount = PlayerStats.instance.bulletAmountCharacteristic;
float rotationZ = 0;
int bulletCnt = 0;
bool isEven = false;
switch (bulletAmount)
{
case 1:
bulletCnt = 1;
break;
case 2:
bulletCnt = 2;
isEven = true;
break;
case 3:
rotationZ = 20;
bulletCnt = bulletAmount;
break;
case 4:
rotationZ = 20;
bulletCnt = bulletAmount - 2;
isEven = true;
break;
case 5:
rotationZ = 40;
bulletCnt = bulletAmount;
break;
case 6:
rotationZ = 40;
bulletCnt = bulletAmount - 2;
isEven = true;
break;
case 7:
rotationZ = 60;
bulletCnt = bulletAmount;
break;
case 8:
rotationZ = 60;
bulletCnt = bulletAmount - 2;
isEven = true;
break;
case 9:
rotationZ = 80;
bulletCnt = bulletAmount;
break;
case 10:
rotationZ = 80;
bulletCnt = bulletAmount - 2;
isEven = true;
break;
default:
break;
}
if (isEven)
{
for (int i = 0; i < 2; i++)
{
var go = Instantiate(this.bulletGo);
go.transform.rotation = this.lookRotation;
go.GetComponent<Bullet>().Init();
go.transform.position = this.bulletPoints[i].transform.position;
}
}
for (int i = 0; i < bulletCnt; i++)
{
if (bulletAmount == 2) continue;
var rotation = Quaternion.Euler(0, 0, rotationZ);
var go = Instantiate(this.bulletGo);
go.transform.rotation = this.lookRotation * rotation;
go.GetComponent<Bullet>().Init();
go.transform.position = this.bulletPoint.transform.position;
if (isEven && rotationZ == 20) rotationZ = 0;
rotationZ -= 20;
}
switch문을 사용하여 간단하게 구현하였습니다.