Пример #1
0
        void Start()
        {
            AStar.SetAllNodes();

            theTransform = GetComponent <Transform>();
            Transform       enemyTransform = enemy.GetComponent <Transform>();
            SprintContainer sprinter       = GetComponent <SprintContainer>();

            //Boolean Checks
            CanSeeEnemy  seeEnemy          = new CanSeeEnemy(theTransform, enemyTransform);
            CloserToHome closerHome        = new CloserToHome(theTransform, enemyTransform, teamFlagNode);
            FlagCaptured teamFlagCaptured  = new FlagCaptured(teamFlag);
            FlagCaptured enemyFlagCaptured = new FlagCaptured(enemyFlag);

            //Movement Leaves
            GoToBase      returnHome  = new GoToBase(theTransform, enemyTransform, sprinter, teamFlagNode);
            SeekEnemyFlag getFlag     = new SeekEnemyFlag(theTransform, sprinter, enemyFlagNode);
            ChaseEnemy    followEnemy = new ChaseEnemy(theTransform, enemyTransform, sprinter);
            TrackEnemy    findEnemy   = new TrackEnemy(theTransform, sprinter, teamFlagNode, enemyFlagNode);

            //Do this if team flag not captured
            Sequence regularReturnHome = new Sequence(new List <Routine> {
                enemyFlagCaptured, returnHome
            });
            Selector flagNotCapturedSelector = new Selector(new List <Routine> {
                regularReturnHome, getFlag
            });

            //Do this if team flag captured
            Sequence closerHomeSequence = new Sequence(new List <Routine>()
            {
                closerHome, returnHome
            });
            Sequence seeEnemySequence = new Sequence(new List <Routine>()
            {
                seeEnemy, followEnemy
            });
            Selector seeEnemySelector = new Selector(new List <Routine>()
            {
                seeEnemySequence, findEnemy
            });
            Selector haveFlagSelector = new Selector(new List <Routine>()
            {
                closerHomeSequence, seeEnemySelector
            });
            Sequence haveFlagSequence = new Sequence(new List <Routine>()
            {
                enemyFlagCaptured, haveFlagSelector
            });
            Selector flagCapturedSelector = new Selector(new List <Routine>()
            {
                haveFlagSequence, seeEnemySelector
            });
            Sequence flagCapturedSequence = new Sequence(new List <Routine>()
            {
                teamFlagCaptured, flagCapturedSelector
            });

            tree = new Selector(new List <Routine>()
            {
                flagCapturedSequence, flagNotCapturedSelector
            });
        }
Пример #2
0
 private void Start()
 {
     chaseEnemy = GetComponentInParent <ChaseEnemy>(); //ChasEnemyスクリプトの取得
     groundInfo = GetComponentInParent <GroundInfo>(); //地面の情報を取得
 }
    // Update is called once per frame
    void Update()
    {
        Ball = GameObject.Find("Football(Clone)");

        bossScript = transform.GetComponent <ChaseEnemy>();
        //bossScript.moveRight = false;
        if (bossScript.moveRight == true && newDirection == false)
        {
            //Bullet_Emitter.transform.position = Vector3.MoveTowards;
            Bullet_Emitter.transform.position = new Vector3(Bullet_Emitter.transform.position.x + 1, Bullet_Emitter.transform.position.y, Bullet_Emitter.transform.position.z);
            newDirection = true;
        }
        else if (bossScript.moveRight == false && newDirection == true)
        {
            //Bullet_Emitter.transform.position = Vector3.MoveTowards;
            Bullet_Emitter.transform.position = new Vector3(Bullet_Emitter.transform.position.x, Bullet_Emitter.transform.position.y, Bullet_Emitter.transform.position.z);
            newDirection = false;
        }

        if (Temporary_Bullet_Handler == null)
        {
            //The Bullet instantiation happens here.
            Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
            //Sometimes bullets may appear rotated incorrectly due to the way its pivot was set from the original modeling package.
            //This is EASILY corrected here, you might have to rotate it from a different axis and or angle based on your particular mesh.
            Temporary_Bullet_Handler.transform.Rotate(Vector3.left);

            //Retrieve the Rigidbody component from the instantiated Bullet and control it.

            Temporary_RigidBody       = Temporary_Bullet_Handler.GetComponent <Rigidbody2D>();
            Temporary_Sprite_Renderer = Temporary_Bullet_Handler.GetComponent <SpriteRenderer>();

            //Tell the bullet to be "pushed" forward by an amount set by Bullet_Forward_Force.
            if (newDirection == false)
            {
                Temporary_RigidBody.AddForce(-transform.right * Bullet_Forward_Force);
                Temporary_Sprite_Renderer.flipX = false;
            }
            else if (newDirection == true)
            {
                Temporary_RigidBody.AddForce(transform.right * Bullet_Forward_Force);
                Temporary_Sprite_Renderer.flipX = true;
            }

            temp = Temporary_RigidBody;
            Destroy(Temporary_Bullet_Handler, 2f);
        }
        if (newDirection == false)
        {
            if (Ball != null && Ball.transform.position.x >= transform.position.x && Ball.transform.position.y <= transform.position.y + 1)
            {
                Destroy(transform.gameObject);
                Destroy(Ball.gameObject);
                counts.enemiesDead++;
            }
        }
        else if (newDirection == true)
        {
            if (Ball != null && Ball.transform.position.x <= transform.position.x && Ball.transform.position.y <= transform.position.y + 1)
            {
                Destroy(transform.gameObject);
                Destroy(Ball.gameObject);
                counts.enemiesDead++;
            }
        }
    }