Question by
unity_65F39AC26ABBF594E9FB · May 02 at 07:30 PM ·
2d2d gameunity 2d
how can I make my bubbles created by this wave spawner move as it is preset in its movement script, because now it only creates them in their respective spawn point, but it doesn't move to the end point.
Hey, I hope someone can help me. :3 ,This is the script for the WaveSpawn
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Wave
{
public string waveName;
public int numOfBubbles;
public GameObject[] typeOfEnemies;
public float spawnInterval;
}
public class WaveSpawn : MonoBehaviour
{
//all the waves we ever gonna have
public Wave[] waves;
public Transform[] spawnPoints;
private Wave currentWave;
// check in what wave are you current in
private int currentWaveNumber;
private float nextSpawnTime;
private bool canSpawn = true;
private void Update()
{
currentWave = waves[currentWaveNumber];
SpawnWave();
GameObject[] totalBubbles = GameObject.FindGameObjectsWithTag("bubbles");
if (totalBubbles.Length == 0 && !canSpawn && currentWaveNumber + 1 != waves.Length)
{
currentWaveNumber++;
canSpawn = true;
}
}
void SpawnWave()
{
if(canSpawn && nextSpawnTime < Time.time)
{
GameObject randomEnemy = currentWave.typeOfEnemies[Random.Range(0, currentWave.typeOfEnemies.Length)];
Transform randomPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];
Instantiate(randomEnemy, randomPoint.position, Quaternion.identity);
currentWave.numOfBubbles--;
if (currentWave.numOfBubbles == 0)
{
canSpawn = false;
}
}
}
}
And this is the script for the movement of the bubbles
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class burbujaBehaibour : MonoBehaviour
{
//public float timeOfArrival;
//Transforms to act as start and end markers for the journey.
public Transform startMarker;
public Transform endMarker;
//que referencie los endpoints de waveSpawn para moverse y los defino en
// Movement speed in units per second
public float speed = 0.1F;
// * maybe i can used my speed formula with the bpm
// Time when the movement started
private float startTime;
// * when starts to play the drumset - time to the bubble to arrive to the button
//total distance between the markers
private float journeyLength;
void Start()
{
//keep a note of the time the movement started
startTime = Time.time;
//GameObject[] endMarkers = GameObject.FindGameObjectstWithTag("endpoint");//encontrar el objecto y el script del objecto
//calculate the journey length
journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
}
// Move to the target end position
void Update()
{
// Distance moved equals elapsed time times speed
float distCovered = (Time.time - startTime) * speed;
// Fraction of journey completed equals current distance divided by total distance
float fractionOfJourney = distCovered / journeyLength;
//Set our position as a fraction of the distance between the markers
transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fractionOfJourney);
{
}
Comment
Your answer
Follow this Question
Related Questions
2D Platformer Projectile wont face mouse position? 0 Answers
Why isn't my BoxCollider2D doing anything? 2 Answers
Virtual controller and fire bullet shot in 2D 0 Answers
how to make my 2d top down character face the direction of the cursor 1 Answer
Problem with tracking multiple object with multitouch 0 Answers