using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Nave : MonoBehaviour
{
[Header("Shooters")]
public Transform Shooter1;
public Transform Shooter2;
public Transform Shooter3;
public Transform Shooter4;
public Transform Shooter5;
public Transform Shooter6;
public Transform Shooter7;
public Transform Shooter8;
public Transform Shooter9;
public Transform Shooter10;
[Header("Raycast Settings")]
public float Raycast_size; // This is the size of the
public LayerMask Player; // This mask is for the player
[Header("Movement Settings")]
public float StartShipMovement;
[Header("Music")]
public AudioBehaviour Hooter;
[Header("Bools")]
public bool Movement_on;// This controls if the starship moves or not
public bool Shoot_On; // This bool controls when the starhip can start to shoot
public bool Move; //This bool controls if the player starship can move constantly
public bool hasspawned;
[Header("Shoot_Settings")]
[SerializeField] private GameObject bullet; // The prefab of the bullet
private GameObject bullet_copy;
public float speed_bullets; // How fast the bullets wil go
public int x;
[Header("Delay_Settings")]
public float Delay_Time;
// Start is called before the first frame update
void Start()
{
Movement_on = false; // At the begining the ship doesn't move
Shoot_On = false; // At the begining the ship does't move
hasspawned = false;
}
public void Update()
{
Movement_on = Physics.CheckSphere(transform.position, Raycast_size, Player); // This bool checks if the player is close
if (Movement_on)
{
Move = true;
}
if(Move)
{
GetComponent<AudioSource>().Play();
transform.position += new Vector3(-StartShipMovement * Time.deltaTime, 0, 0);
StartCoroutine("Ship_Movement");
}
}
// Update is called once per frame
IEnumerator Ship_Movement() //
{
yield return new WaitForSeconds(Delay_Time);
GetComponent<AudioSource>().Stop();
if (hasspawned)
{
bullet_copy = Instantiate(bullet, Shooter1.transform.position, Quaternion.identity);
Debug.Log("It should work");
hasspawned = false;
}
hasspawned = true;
}
public void OnDrawGizmos()
{
Gizmos.DrawWireSphere(transform.position, Raycast_size);
}
}
I`m trying to make my best , sorry. This is my code for a starhip that should be shooting only once after some time . My problem comes when it starts shoot , it shoots until the delay ends and my desire is that shoots only once.
Every function works fine and the debug log shows me the message but the statment of hasspawned doesnt’ change after showing the message.