Cosmic Strike
 
Cargando...
Buscando...
Nada coincide
RadialShot.cs
Ir a la documentación de este archivo.
1
10
11using UnityEngine;
12
19{
24 [Header("Radial Shot Settings")]
25 [Tooltip("Prefab del proyectil (GameObject con Rigidbody2D + DamageOnTrigger)")]
26 public GameObject bulletPrefab;
27
32 [Tooltip("Punto central de salida (Transform hijo de la nave)")]
33 public Transform firePoint;
34
38 [Tooltip("Velocidad de salida de cada proyectil")]
39 public float bulletSpeed = 8f;
40
44 [Tooltip("Número de proyectiles en la circunferencia")]
45 public int bulletCount = 12;
46
51 void Awake()
52 {
53 if (firePoint == null)
54 {
55 var playerGO = GameObject.Find("Player");
56 if (playerGO != null)
57 {
58 var fp = playerGO.transform.Find("FirePointCenter");
59 if (fp != null)
60 {
61 firePoint = fp;
62 }
63 else
64 {
65 Debug.LogError("RadialShot: no se encontró 'FirePointCenter' bajo 'Player'.");
66 }
67 }
68 else
69 {
70 Debug.LogError("RadialShot: no se encontró ningún GameObject llamado 'Player'.");
71 }
72 }
73 }
74
79 public override void Shoot()
80 {
81 if (bulletPrefab == null || firePoint == null || bulletCount < 1)
82 {
83 Debug.LogWarning("RadialShot: configura bulletPrefab, firePoint y bulletCount ≥ 1.");
84 return;
85 }
86
87 float angleStep = 360f / bulletCount;
88 float angle = 0f;
89
90 for (int i = 0; i < bulletCount; i++)
91 {
92 // Calcula la rotación y dirección
93 Quaternion rot = Quaternion.Euler(0f, 0f, angle);
94 Vector2 dir = rot * Vector2.up;
95
96 // Instancia el proyectil
97 GameObject b = Instantiate(bulletPrefab, firePoint.position, rot);
98 if (b.TryGetComponent<Rigidbody2D>(out var rb))
99 {
100 rb.linearVelocity = dir * bulletSpeed;
101 }
102 else
103 {
104 Debug.LogWarning("RadialShot: el prefab no tiene Rigidbody2D.");
105 }
106
107 angle += angleStep;
108 }
109 }
110}
Implementación de disparo radial que instancia bulletCount proyectiles equiespaciados en un círculo c...
Definition RadialShot.cs:19
float bulletSpeed
Velocidad a la que se desplaza cada proyectil en la dirección asignada.
Definition RadialShot.cs:39
Transform firePoint
Transform desde donde se dispararán todos los proyectiles. Si no se asigna manualmente,...
Definition RadialShot.cs:33
int bulletCount
Número total de proyectiles generados en la circunferencia.
Definition RadialShot.cs:45
void Awake()
Si no se ha asignado un firePoint manualmente, se busca automáticamente el hijo "FirePointCenter" den...
Definition RadialShot.cs:51
GameObject bulletPrefab
Prefab del proyectil que se dispara radialmente. Debe tener un Rigidbody2D para aplicar velocidad.
Definition RadialShot.cs:26
override void Shoot()
Ejecuta el disparo radial. Instancia bulletCount proyectiles y les asigna una velocidad en direccione...
Definition RadialShot.cs:79
Clase base abstracta que define la interfaz de comportamiento para proyectiles. Cada clase hija debe ...