コード例 #1
0
    // public bool isCorrectWithMap(Vector2 pos, Vector2[] direct)
    // {

    //     for (int i = 0; i < direct.Length; i++)
    //     {
    //         RaycastHit2D hits;
    //         hits = Physics2D.Raycast(pos, direct[i], 100f, 9);
    //         if (hits == null)
    //         {
    //             return false;
    //         }

    //     }

    //     // RaycastHit2D circleCast = Physics2D.CircleCast(pos, 1f, Vector2.zero, 10, 0);
    //     // if (circleCast.point != Vector2.zero)
    //     // {
    //     //     Debug.Log(circleCast.collider.gameObject.name);
    //     // }

    //     return true;
    // }
    void Spawn(GameObject gameObject, int index)
    {
        // spawn Enemy prefab
        var randomPos = (Vector3)Random.insideUnitCircle * 6;

        // while (!isCorrectWithMap(randomPos, direct))
        // {
        //     randomPos = (Vector3)Random.insideUnitCircle * 10;
        // }
        // RaycastHit2D[] hits1 = Physics2D.RaycastAll(randomPos, -Vector2.up);

        if (index > 5)
        {
            randomPos = (Vector3)map.GetComponent <MapControler>().listPointSpawn[index - 6];
        }
        else if (index > 0 && map != null)
        {
            randomPos = SpawnPos();
        }
        else if (index == 0)
        {
            randomPos += (Vector3)map.GetComponent <MapControler>().listPointSpawn[Random.Range(0, 6)];
        }

        GameObject ene = Instantiate(gameObject, randomPos, Quaternion.identity);

        ene.transform.parent = spawnHolder;

        BallController eneAssigned = ene.GetComponent <BallController>();

        eneAssigned.OnSpawn(GameController.Instance.characters[index]);

        // spawn name for enemy
        GameObject nameControl = Instantiate(namePre, Vector3.zero, Quaternion.identity);

        nameControl.transform.parent     = nameHolder;
        nameControl.transform.localScale = Vector3.one;

        NameController nameControlCpn = nameControl.GetComponent <NameController>();

        nameControlCpn.target = ene;
        nameControlCpn.OnSpawn(eneAssigned.infor);

        if (!eneAssigned.infor.isPLayer)
        {
            // spawn point direction to enemy
            GameObject point = Instantiate(Point, Vector3.zero, Quaternion.identity);
            point.transform.parent     = pointHolder;
            point.transform.localScale = Vector3.one;
            point.GetComponent <WindowQuestPoint>().goTarget      = ene.transform;
            point.GetComponent <WindowQuestPoint>().textMesh.text = eneAssigned.infor.itemName;
            // }
            // else
            // {
            //     var scr = ene.GetComponent<Player>();
        }

        eneAssigned.skeletonAnimation.skeletonDataAsset = eneAssigned.infor.dataAsset;
        eneAssigned.skeletonAnimation.Initialize(true);

        GameController.Instance.listObject.Add(ene);
        GameController.Instance.listBallController.Add(eneAssigned);
    }