コード例 #1
0
    private void SpawnFighter(GameObject fighterPosition)
    {
        var fighter      = Instantiate(GameManager.Instance.characters[(int)agent.team].fighterPrefab, fighterPosition.transform.position, Quaternion.identity) as GameObject;
        var fighterAgent = fighter.GetComponent <AgentManager>();

        fighterAgent.team = agent.team;
        fighterAgent.Start();

        var behaviour = new FighterBehaviour();

        behaviour.target = fighterPosition;

        fighterAgent.mover.AddBehaviour(behaviour);
        NetworkServer.Spawn(fighter);
    }
コード例 #2
0
ファイル: FighterBehaviour.cs プロジェクト: Gr8th1ngy/Maat
    protected List <FighterBehaviour> LookForOpponent(LayerMask opponentLayerMask)
    {
        List <FighterBehaviour> opponents = new List <FighterBehaviour>();
        var colliders = Physics.OverlapSphere(transform.position, detectionRange, opponentLayerMask);

        foreach (var collider in colliders)
        {
            FighterBehaviour opponent = collider.GetComponentInParent <FighterBehaviour>();
            if (opponent != null)
            {
                opponents.Add(opponent);
            }
        }

        return(opponents);
    }
 public FighterBehaviourDecorator(AbstractBehaviourComponent parentBehaviour, MovementBehaviour behaviour)
     : base(parentBehaviour, behaviour)
 {
     this.behaviour = behaviour as FighterBehaviour;
 }
コード例 #4
0
ファイル: GameManager.cs プロジェクト: Jaffark/BurningSky
    void SpawnAI()
    {
        //If Player is not active we will not spawn the player
        if (!player.gameObject.activeInHierarchy)
        {
            return;
        }
        //Inorder to give delay between spawn we compare the last spawn time with current time
        if (Time.time > lastSpawnTime + delayBetweenSpawn)
        {
            //Just to Random spawn Style
            //The Spawn Style will define whether to spawn only 1,multiple and rightleft(We will define rightleft in v0.2).
            int random = Random.Range(1, 101);
            currentSpawnSytle = spawnStyle.single;
            //If random value is greater than 50 we set the spawn style to multiple
            if (random > 50)
            {
                currentSpawnSytle = spawnStyle.multiple;
            }
            //This expectedZ will hold the value of z value to spawn fighter at z
            float expectedZ = 17;
            //In order to avoid more number of Fighter overlaping we set some offset between the Spawn Fighter
            float offsetBetweenFighters = 3;
            //We will compare to make it more accurate offset
            if (lastSpawnFighterPlane && lastSpawnFighterPlane.transform.position.z > 17 - offsetBetweenFighters)
            {
                expectedZ = lastSpawnFighterPlane.transform.position.z + offsetBetweenFighters;
            }
            //If expected z spawn value is more we will ignore the spawn just to avoid more number of unnessary spawn in background
            if (expectedZ > 35)
            {
                return;
            }
            //Set the lastSpawnTime to current Time
            lastSpawnTime = Time.time;
            //Comparing the current Spawn Style and then loading base on that
            switch (currentSpawnSytle)
            {
            case spawnStyle.single:
                //In Sigle spawn we will randomize the Fighters base on some values
                int randomFighter = Random.Range(1, 101);
                //If randomFighter is less then 30 we willl spawn the Fighter AI 1 and so on
                if (randomFighter <= 30)
                {
                    //Instead of spawning fighter every time we will check for disabled one using GetFighterPlane
                    newAi = GetFighterPlane(1);
                    //If its null we spawn
                    if (newAi == null)
                    {
                        //Ai Fighter with Only Forward Be
                        newAi = Instantiate(aiFighter1);
                        listOfFighterPlane1.Add(newAi.GetComponent <EnemyController>());
                    }
                }
                else if (randomFighter <= 60)
                {
                    newAi = GetFighterPlane(2);
                    if (newAi == null)
                    {
                        newAi = Instantiate(aiFighter2);
                        listOfFighterPlane2.Add(newAi.GetComponent <EnemyController>());
                    }
                }
                else if (randomFighter <= 80)
                {
                    newAi = GetFighterPlane(3);
                    if (newAi == null)
                    {
                        newAi = Instantiate(aiFighter3);
                        listOfFighterPlane3.Add(newAi.GetComponent <EnemyController>());
                    }
                }
                else
                {
                    newAi = GetFighterPlane(4);
                    if (newAi == null)
                    {
                        newAi = Instantiate(aiFighter4);
                        listOfFighterPlane3.Add(newAi.GetComponent <EnemyController>());
                    }
                }
                //We will set the x position to random between -3.8f to 3.8f as we dont want to spawn out of Screen X
                newAi.transform.position = new Vector3(Random.Range(-3.8f, 3.8f), 0, expectedZ);

                //Setting Fighter Ai active  to true
                newAi.SetActive(true);
                //Setting lastSpawnFighterPlane as this newAI
                lastSpawnFighterPlane = newAi;
                break;

            case spawnStyle.multiple:
                //In this we will spawn multiple AI Fighter1
                //Since we will spawn with some distance in z direction
                float lastZVal = expectedZ;
                //We define distance between two to make it come in sequence
                float distanceBetweenTwo = 3;
                //We don't want sequence to come in different x value so we will define common random value for all Fighter AI
                float lastXVal = Random.Range(-3.8f, 3.8f);
                //V0.2 Added Ramdom Behaviour
                int randomBehaviour = Random.Range(1, 5);      //1-4
                for (int i = 0; i < 3; i++)
                {
                    //We will try to get the Fighter AI from list
                    newAi = GetFighterPlane(1);
                    if (newAi == null)
                    {
                        newAi = Instantiate(aiFighter1); //V0.2 Giving variation in behaviour
                    }
                    FighterBehaviour behaviour = newAi.GetComponent <FighterBehaviour>();
                    switch (randomBehaviour)
                    {
                    case 1:
                        behaviour.fighterBehaviour = eFighterBehaviour.Straight;
                        break;

                    case 2:
                        behaviour.fighterBehaviour = eFighterBehaviour.GoLeft;
                        behaviour.pointToMove      = new Vector3(-11, 0, 5);
                        behaviour.speed            = 12f;
                        behaviour.behaviourWhenZ   = Random.Range(6, 8);
                        break;

                    case 3:
                        behaviour.fighterBehaviour = eFighterBehaviour.GoRight;
                        behaviour.pointToMove      = new Vector3(11, 0, 5);
                        behaviour.speed            = 12f;
                        behaviour.behaviourWhenZ   = Random.Range(6, 8);
                        break;

                    case 4:
                        behaviour.fighterBehaviour = eFighterBehaviour.ZigZag;
                        behaviour.speed            = 0.5f;

                        break;
                    }
                    //We multiple z value with i inorder to get the difference in z value
                    newAi.transform.position = new Vector3(lastXVal, 0, lastZVal + (i * distanceBetweenTwo));
                    newAi.SetActive(true);
                    lastSpawnFighterPlane = newAi;
                }
                //Just to avoid more number of spawn which will make
                lastSpawnTime = delayBetweenSpawn * 3;
                break;
            }
        }
    }