Cosmic Strike
 
Cargando...
Buscando...
Nada coincide
AlternatingShot.cs
Ir a la documentación de este archivo.
1
8
9using UnityEngine;
10
16{
17 // ========== CONFIGURACIÓN DEL DISPARO ==========
18
23 [Header("AlternatingShot")]
24 public GameObject bulletPrefab;
25
29 public float bulletSpeed = 10f;
30
35 [Tooltip("Arrastra manualmente Left, Right si quieres, sino se cogerán del Player")]
36 public Transform[] firePoints;
37
38 // ========== VARIABLES INTERNAS ==========
39
44 private int nextIndex;
45
46 // ========== MÉTODOS UNITY ==========
47
52 void Awake()
53 {
54 if (firePoints == null || firePoints.Length < 2)
55 {
56 // Asumimos que el arma está bajo el Player
57 Transform playerRoot = transform.root;
58 Transform left = playerRoot.Find("FirePointLeft");
59 Transform right = playerRoot.Find("FirePointRight");
60
61 if (left != null && right != null)
62 firePoints = new Transform[] { left, right };
63 else
64 Debug.LogError(
65 $"[{name}] AlternatingShot Awake: no ha encontrado FirePointLeft/Right bajo {playerRoot.name}"
66 );
67 }
68 }
69
74 public override void Shoot()
75 {
76 if (firePoints == null || firePoints.Length < 2 || bulletPrefab == null)
77 return;
78
79 // Selecciona y dispara
80 Transform fp = firePoints[nextIndex];
81 GameObject b = Instantiate(bulletPrefab, fp.position, fp.rotation);
82 if (b.TryGetComponent<Rigidbody2D>(out var rb))
83 rb.linearVelocity = fp.up * bulletSpeed;
84
85 // Prepara el siguiente índice (0→1→0…)
86 nextIndex = (nextIndex + 1) % firePoints.Length;
87 }
88}
Comportamiento de disparo que alterna entre dos puntos de disparo (por ejemplo, izquierdo y derecho)....
Transform[] firePoints
Transformaciones que indican desde dónde se disparan los proyectiles. Si no se arrastran manualmente,...
override void Shoot()
Dispara un proyectil desde el siguiente firePoint, alternando entre los disponibles....
void Awake()
Busca automáticamente los firePoints si no se han asignado manualmente. Se asume que el arma está ani...
int nextIndex
Índice del próximo firePoint desde el que se disparará. Se alterna entre 0 y 1 en cada disparo.
GameObject bulletPrefab
Prefab del proyectil que se instanciará al disparar. Debe tener un Rigidbody2D para que se le aplique...
float bulletSpeed
Velocidad con la que se desplaza el proyectil al ser disparado (en unidades por segundo).
Clase base abstracta que define la interfaz de comportamiento para proyectiles. Cada clase hija debe ...