dimanche 29 juillet 2018

Random Position Spawning

I am currently using the unity tanks game tutorial and have been working on improving it and I am working on having a random tank spawn. It works by choosing a random spawn point for tank 1 and then for tank 2 adds one to the generator to choose the next spawn point so to get rid of the chance of having the same spawn point for both tanks yet both tanks occasionally get the same spawn point. So I was wondering on how to fix this and make the tanks spawn at a random place instead of spawning at the same one

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public int m_NumRoundsToWin = 5;        
    public float m_StartDelay = 3f;         
    public float m_EndDelay = 3f;           
    public CameraControl m_CameraControl;   
    public Text m_MessageText;              
    public GameObject m_TankPrefab;         
    public TankManager[] m_Tanks;
    public Transform[] m_SpawnPoints;           


    private int m_RoundNumber;              
    private WaitForSeconds m_StartWait;     
    private WaitForSeconds m_EndWait;       
    private TankManager m_RoundWinner;
    private TankManager m_GameWinner; 

private void SpawnAllTanks()
{
int spawn = Random.Range(0, 666);
    for (int i = 0; i < m_Tanks.Length; i++)
    {
        m_Tanks[i].m_SpawnPoint.rotation) as GameObject;
           m_Tanks[i].m_Instance =
                    Instantiate(m_TankPrefab, m_SpawnPoints[(spawn + i) % 6].position, m_Tanks[i].m_SpawnPoint.rotation) as GameObject;
                    print("Choosing Spawn"+(spawn + i) % 6);
        m_Tanks[i].m_PlayerNumber = i + 1;
        m_Tanks[i].m_SpawnPoint.position =m_SpawnPoints[(spawn + i) % 6].position;
        m_Tanks[i].Setup();

    }
}




Aucun commentaire:

Enregistrer un commentaire