0% found this document useful (0 votes)
488 views3 pages

Enemy Spawner Script 1

Uploaded by

saad3102004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
488 views3 pages

Enemy Spawner Script 1

Uploaded by

saad3102004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System.

Collections;

using System.Collections.Generic;

using UnityEngine;

public class Enemyspawner : MonoBehaviour

public static Transform[] spawnpoints;

//variable for storing distance between the player and the spawn point

public float DBTP;

//variable for refrencing the spawn points one after the other

private Transform Sp;

//enemy prefab

public GameObject Enemyprefab;

//index of spawnpoints array

public int spawnpointindex = 0;

//least distance after which the enemy is going to get spawned

public float DBS;

//spawn points children parent

public Transform spawnerparent;

public Enemymovement emscript;

// Start is called before the first frame update

void Start()
{

//Getting the spawnpoints child from the parent spawnerparent

spawnpoints = new Transform[spawnerparent.childCount];

for(int i = 0; i < spawnpoints.Length; i++)

spawnpoints[i] = spawnerparent.GetChild(i);

//Setting the spawn points one by one according to the index

Sp = spawnpoints[0];

// Update is called once per frame

void Update()

//Calculating distance between the player and the spawn point

DBTP = Sp.position.x - transform.position.x;

//checking if the least distance have reached to spawn in the enemy

if (DBTP <= DBS)

//test message before instanciating the enemy in the scene

Debug.Log("1st Enemy reached");

//function to load the next spawnpoint after the first one is reached
emscript.Espeed = -2;

next();

void next()

if (spawnpointindex >= spawnpoints.Length)

spawnpointindex++;

Sp = spawnpoints[spawnpointindex];

You might also like