게임클라이언트 프로그래밍/R&D
Bullet Pattern R&D(360도 회전, Double Spiral)
Game Client Lee Hwanguk
2023. 3. 26. 23:45
*레퍼런스 보스 패턴
*참고 영상
https://www.youtube.com/watch?v=5dlEl_G713A&list=PL78jMnwPOfjAtIdma8F26AQdJGwydtI80&index=3&t=53s
*구현 영상 (inspector에서 조절 가능하게)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletTest3 : MonoBehaviour
{
[SerializeField]
private float repeatRate = 0.2f;
[SerializeField]
private float repeatTime = 0f;
[SerializeField]
private float angle = 0f;
[SerializeField]
private float pluseAngle = 10f;
//private Vector2 bulletMoveDirection;
void Start()
{
InvokeRepeating("Fire", this.repeatTime, this.repeatRate);
}
private void Fire()
{
for (int i = 0; i <= 1; i++)
{
float bulDirX = this.transform.position.x + Mathf.Sin(((angle+180f*i)*Mathf.PI)/180f);
float bulDirY = this.transform.position.y + Mathf.Cos(((angle + 180f * i) * Mathf.PI) / 180f);
Vector3 bulMoveVector=new Vector3(bulDirX,bulDirY, 0f); //Vector
Vector2 bulDir = (bulMoveVector - this.transform.position).normalized; //Direction
GameObject bul = BulletPool.bulletPoolInstance.GetBullet(); //pooling
bul.transform.position=this.transform.position;
bul.transform.rotation=this.transform.rotation;
bul.SetActive(true);
bul.GetComponent<Bullet>().SetMoveDirection(bulDir); //bul direction
}
this.angle += this.pluseAngle; //angle을 pluseAngle만큼 늘려가며 호출
if (angle>=360f) //360도 초과면 0으로 초기화
{
angle = 0f;
}
}
}