Quantcast
Channel: Questions in topic: "endless"
Viewing all articles
Browse latest Browse all 123

Make an enemy generator

$
0
0
I'm trying to make an endless game where the player can only move in 3 specific lanes (up, mid, and down) and try to survive the enemies coming from these lanes. The main problem it's i don't know how to make an enemy generator... This is the player movement: using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement : MonoBehaviour { GameObject SpawnCentrale; GameObject SpawnBasso; GameObject SpawnAlto; // Start is called before the first frame update void Start() { SpawnCentrale = GameObject.FindWithTag("Spawn1"); SpawnBasso = GameObject.FindWithTag("Spawn2"); SpawnAlto = GameObject.FindWithTag("Spawn3"); transform.position = GameObject.Find("Spawn1").transform.position; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.W) && transform.position == SpawnCentrale.transform.position) { transform.position = GameObject.Find("Spawn3").transform.position; } if (Input.GetKeyDown(KeyCode.W) && transform.position == SpawnBasso.transform.position) { transform.position = GameObject.Find("Spawn1").transform.position; } if (Input.GetKeyDown(KeyCode.S) && transform.position == SpawnCentrale.transform.position) { transform.position = GameObject.Find("Spawn2").transform.position; } if (Input.GetKeyDown(KeyCode.S) && transform.position == SpawnAlto.transform.position) { transform.position = GameObject.Find("Spawn1").transform.position; } } } This is the enemy movement (for just one lane): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { public float speed = 5.0f; private Rigidbody2D rb; GameObject CancellaNemici; // Start is called before the first frame update void Start() { rb = this.GetComponent(); rb.velocity = new Vector2(-speed, 0); CancellaNemici = GameObject.FindWithTag("DeleteEnemy"); } // Update is called once per frame void Update() { if (transform.position.x < CancellaNemici.transform.position.x){ Destroy(this.gameObject); } } } And this is my attempt to make an enemy generator, but it's not working: using System.Collections; using System.Collections.Generic; using UnityEngine; public class DeployEnemy : MonoBehaviour { public GameObject EnemyPrefab; GameObject EnemySpawn; void Start() { StartCoroutine(SpawnObjects()); EnemySpawn = GameObject.FindWithTag("SpawnEnemy"); } IEnumerator SpawnObjects() { while (true) { Instantiate(EnemyPrefab, EnemySpawn.transform.position, Quaternion.identity); yield return new WaitForSeconds(3.0f); } } } I'm new to game development and programming in general so i'm really lost >_<

Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>