Y
Y
yraiv2022-01-28 09:08:41
Unity
yraiv, 2022-01-28 09:08:41

Why is the object spawned somewhere far away and not at the spawn point?

All prefabs are at zero coordinates. Maybe I'm not creating the object correctly somehow? I want it to spawn at the spawn point

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Manager : MonoBehaviour
{

    public int Health;
    public int Money;
    public GameObject FinishPoint;
    public GameObject[] ZombieType;
    public GameObject SpawnPoint;
    public int Rounds;
    public float TimeStep;
    public Transform FinishPos;
    public int NomberZombie;
    void Start()
    {
        Health = 100;
        Money = 200;
        FinishPos = FinishPoint.GetComponent<Transform>();
        StartCoroutine(SpawnMob());
    }

    void Repeat()
    {
        StartCoroutine(SpawnMob());

    }



    IEnumerator SpawnMob()
    {
        yield return new WaitForSeconds(TimeStep);
        Instantiate(ZombieType[NomberZombie], FinishPos.position, Quaternion.identity);
        Repeat();
    }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question