Esempio n. 1
0
    void SpawnBozu()
    {
        if (bozuAmt < maxBozuAmt)
        {
            float spawnX = Random.Range(minX, maxX);
            float spawnZ = Random.Range(minZ, maxZ);
            float spawnY = yCoord;


            Ray        ray = new Ray(new Vector3(spawnX, 100f, spawnZ), Vector3.down);
            RaycastHit hit;

            bool wallCollide = false;

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.tag.Equals("wall"))
                {
                    wallCollide = true;
                    SpawnBozu();
                }
            }

            Vector3 spawnLoc = new Vector3(spawnX, spawnY, spawnZ);
            if (!wallCollide && (player == null || Vector3.Distance(spawnLoc, player.transform.position) > 40f))
            {
                GameObject  current = Instantiate(bozu, spawnLoc, Quaternion.identity);
                GhostScript ghost   = current.GetComponent <GhostScript>();
                ghost.moveSpeed = bozuSpeed;

                bozuAmt++;
                if (bozuWander)
                {
                    ghost.wander = true;
                    ghost.Pause();
                }
            }
            else
            {
                // if (player != null)
                {
                    SpawnBozu();
                }
            }
        }
    }