Unity2D
Unity) [유니티 2D] 3갈래로 발사되는 탄환, 총알 구현
HSH12345
2023. 4. 14. 02:42
float angle = transform.eulerAngles.z % 360;
this.dir = new Vector2(Mathf.Cos(angle * Mathf.Deg2Rad), Mathf.Sin(angle * Mathf.Deg2Rad));
우선 해당 기능을 구현하기 위해 탄환이 Rotation.z 값이 변함에 따 라 항상 정면으로 이동해야한다.
if (PlayerStats.instance.bulletAmountCharacteristic == 3)
{
float rotationZ = 20;
for (int i = 0; i < PlayerStats.instance.bulletAmountCharacteristic; i++)
{
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;
rotationZ -= 20;
}
}
그 이후 탄환을 생성할 때 rotation 값을 각각 지정하여 3갈래로 탄환이 움직이도록 구현한다.