Search Unity

Question Enemies do not collide when spawned with prefab spawner

Discussion in 'Prefabs' started by Deleted User, Feb 26, 2023.

  1. Deleted User

    Deleted User

    Guest

    (If this is the wrong forum please correct me.)
    Hello! I am making a game for school which is a zombie shooter. I have the zombies spawn at an array of spawn points, it all works fine but there are occasions where some of the zombies won't take damage:(. The zombies have a Navmesh, Box Collider, and a Rigidbody. Here is my code concerning the spawning of the zombies:
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Unity.VisualScripting;
    5. using UnityEngine;
    6. public class GameManager : MonoBehaviour
    7. {
    8.     public GameObject obstacle;
    9.     public Transform[] spawnPoint;
    10.     public int amount = 0;
    11.     public GameObject Player;
    12.  
    13.  
    14.     public void Start()
    15.     {
    16.         StartCoroutine("SpawnObstacles");
    17.         //starts the obstacle spawning
    18.     }
    19.  
    20.     private void Update()
    21.     {
    22.         amount = GameObject.FindGameObjectsWithTag("Zombie").Length;
    23.     }
    24.  
    25.  
    26.  
    27.     IEnumerator SpawnObstacles()
    28.     {
    29.  
    30.         while (true)
    31.         {
    32.             for (int i = 0; i < spawnPoint.Length; i++)
    33.             {
    34.                 if (GameObject.FindGameObjectsWithTag("Zombie").Length > 100)
    35.                 {
    36.                     Destroy(Player);
    37.                     //Will add main menu but this is the current method of loosing
    38.                 }
    39.  
    40.  
    41.                 float waitTime = .7f;
    42.                     //sets waitime
    43.                     yield return new WaitForSeconds(waitTime);
    44.                     //pauses before next spawn
    45.                     Instantiate(obstacle, spawnPoint[i].position, Quaternion.identity);              
    46.                    
    47.             }
    48.  
    49.  
    50.         }  
    51.  
    52.     }
    53.  
    54.  
    55.  
    56.  
    57.  
    58.  
    59.  
    60.  
    61. }
    62.  
    If you would like my zombie class and the .asset file I can provide them.
    Thanks!:D
     
  2. Deleted User

    Deleted User

    Guest

    Can someone please help?:(