Как установить расстояние между порожденными сборными домами? - PullRequest
0 голосов
/ 10 июля 2019

Я хочу порождать сборные объекты, но теперь этот объект умножается в одной позиции.Я установил 4 позиции вокруг игрока, и для создания объектов я использую этот код:

public class EnemySpawner : MonoBehaviour {

    public static EnemySpawner instance;

    [SerializeField]
    private int scoreMileStone = 100;                   //this will define number of cars in the scene
    private int milestoneIncreaser = 100;               //this sets new milestone once old is reached

    [SerializeField]
    private Transform[] spawnPos;                       //store all the available spawn position

    [SerializeField]
    private int policeCarRequired;                      //this will tell how much cars are needed in the scene at a time

    private int currentPoliceCar;                       //this variables keep track of total number of cars in the scene
    private GameObject target;                          //store player reference in this variable
    private int lastPosition, r;

    private int lastSpawnPos;

    public int CurrentPoliceCar { get { return currentPoliceCar; } set { currentPoliceCar = value; } }  //getter and setter

    // Use this for initialization
    void Awake ()
    {
        if (instance == null) instance = this;
    }

    // Update is called once per frame
    void Update ()
    {   
        if (GuiManager.instance.GameStarted == false || GuiManager.instance.GameOver == true)
            return;

        if (target == null)                                         //if target is null
        {
            target = GameObject.FindGameObjectWithTag("Player");    //try detecting target again
            return;                                                 //return from the method
        }

        MilestoneIncreaser();                                       //increase milestone

        if (currentPoliceCar < policeCarRequired)                   //if currentPoliceCar is less than policeCarRequired
        {
            SpawnPoliceCar();                                       //spawn police car
        }

    }

    void SpawnPoliceCar()                                           //spawn police car
    {
        GameObject wolf = ObjectPooling.instance.GetPooledObject("Wolf");     //get police car reference from objectpooling
        RandomPos();

        int r = Random.Range (0, spawnPos.Length);
        while(lastSpawnPos == r)
            r = Random.Range (0, spawnPos.Length);

        wolf.transform.position = new Vector3(spawnPos[r].position.x, 0, spawnPos[r].position.z);  //set the transform
        wolf.SetActive(true);                                                      //set it active in scene
        wolf.GetComponent<Damage>().DefaultSetting();                              //call DefaultSettings method
        lastSpawnPos = r;
        currentPoliceCar++;                                                             //increase currentPoliceCar by 1
    }

    void MilestoneIncreaser()                                               //increase the milestone  
    {
        if (GuiManager.instance.Score >= scoreMileStone)                    //if currentScore is greater or equal to scoreMilestone
        {
            scoreMileStone += milestoneIncreaser;                           //increase the milestone 

            if (policeCarRequired < 8)                                      //if max policeCarRequired is less than 8
                policeCarRequired++;                                        //increase policeCarRequired by 1
        }
    }

    void RandomPos()
    {
        int r = Random.Range(0, spawnPos.Length);                                       //get random number between zero and total spawnpos

        while(lastPosition == r)
            r = Random.Range(0, spawnPos.Length);
    }
}

Это дает мне объекты, но без промежутков между ними, объекты появляются, например, 4 в одномположение и 3 в другом, но они сжаты.Можно ли это как-то исправить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...