상속: MonoBehaviour
예제 #1
0
    public void ShootBullet()
    {
        GameObject gO;

        if (index < NumberOfOrangeBullets)
        {
            gO = Utils.InstantiateSafe(OrangeBulletPrefab, transform.position);
        }
        else
        {
            gO = Utils.InstantiateSafe(PurpleBulletPrefab, transform.position);
        }

        if (SpawnMode == BulletSpawnMode.OnTrack)
        {
            //on bullet object - Patroller
            PatrolEnemy e = gO.AddComponent <PatrolEnemy>();
            e.Track = TrackToSpawnOn;
            e.SetTrajectory(0.0f);
            e.MoveSpeed      = BulletSpeed * onTrackBulletSpeedIncrement;
            e.IsNoReverse    = true;
            e.IsDestroyAtEnd = true;

            Bullet b = gO.GetComponent <Bullet>();
            //b.Speed = BulletSpeed; //doesn't do anything because bullets aren't moving on their own.
            b.IsImmortal = true;
        }

        if (SpawnMode == BulletSpawnMode.TowardsPlayer)
        {
            Vector3 playerDirection = Player.position - this.transform.position;
            Bullet  b = gO.GetComponent <Bullet>();
            b.Speed = BulletSpeed;

            if (IsBulletsIgnoreWalls)
            {
                b.IsIgnoreWall = true;
            }
            //move towards player
            b.Move(playerDirection.normalized);
        }

        //parent, can be optimized
        string     name        = this.gameObject.name + " bullet list";
        GameObject groupObject = GameObject.Find(name);

        if (groupObject == null)
        {
            groupObject = new GameObject(name);
        }

        gO.transform.parent = groupObject.transform;
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Generate new patrol path", GUILayout.Height(30)))
        {
            PatrolEnemy p = ((PatrolEnemy)target);

            GameObject newG = new GameObject("Enemy patrol path");
            newG.transform.position = p.transform.position;
            LineTrack l = newG.AddComponent <LineTrack>();
            l.CalculateStartPoints();
            p.Track = l;
        }
    }
    public void TakeDamage(float damage, float invulnPeriod)
    {
        if (!invulnerable)
        {
            health      -= damage;
            invulnerable = true;

            if (health <= 0f)
            {
                //put what you want on death to happen
                if (me.CompareTag("Player"))
                {
                    PlayerScript script = me.GetComponent <PlayerScript>();
                    script.Death();
                }
                if (me.CompareTag("Mech"))
                {
                    MechScript script = me.GetComponent <MechScript>();
                    script.Death();
                }
                //put tags of other items here
                if (me.CompareTag("Patroller"))
                {
                    PatrolEnemy script = me.GetComponent <PatrolEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Flyer"))
                {
                    FlyingEnemy script = me.GetComponent <FlyingEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Bomber"))
                {
                    BomberEnemy script = me.GetComponent <BomberEnemy>();
                    script.Death();
                }
                if (me.CompareTag("Boss"))
                {
                    BossEnemy script = me.GetComponent <BossEnemy>();
                    script.Death();
                }
            }
            else
            {
                Invoke("RemoveInvuln", invulnPeriod);
            }
        }
    }
예제 #4
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PatrolEnemy PE = (PatrolEnemy)target;

        if (GUILayout.Button("Add Current Location to Path: NO Pause"))
        {
            PE.PatrolPoints.Add(PE.transform.position);
            PE.PausePoints.Add(false);
            EditorUtility.SetDirty(PE);
        }
        else if (GUILayout.Button("Add Current Location to Path: WITH Pause"))
        {
            PE.PatrolPoints.Add(PE.transform.position);
            PE.PausePoints.Add(true);
            EditorUtility.SetDirty(PE);
        }

        if (TryingToReset)
        {
            if (GUILayout.Button("Confirm Reset"))
            {
                PE.PatrolPoints = new List <Vector3> ();
                PE.PausePoints  = new List <bool> ();
                EditorUtility.SetDirty(PE);
                TryingToReset = false;
            }
            else if (GUILayout.Button("Cancel"))
            {
                TryingToReset = false;
            }
        }
        else
        {
            if (GUILayout.Button("Reset Patrol Path"))
            {
                TryingToReset = true;
            }
        }
    }
예제 #5
0
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        //check to see if bullet has hit an enemy.
        Enemy enemy = hitInfo.GetComponent <Enemy>();

        //if an enemy is hit
        if (enemy != null)
        {
            enemy.TakeDamage(bulletDmg);
        }

        PatrolEnemy penemy = hitInfo.GetComponent <PatrolEnemy>();

        //if an enemy is hit
        if (penemy != null)
        {
            penemy.TakeDamage(bulletDmg);
        }

        Boss boss = hitInfo.GetComponent <Boss>();

        //if an enemy is hit
        if (boss != null)
        {
            boss.TakeDamage(bulletDmg);
        }

        Player player = hitInfo.GetComponent <Player>();

        //if an player is hit

        /*if (player != null)
         * {
         *  player.PlayerTakeDamage(bulletDmg);
         * }
         */
        Destroy(gameObject);
    }
 public PatrolEnemy_StunState(Entity entity, EntityStateMachine stateMachine, string animBoolName, EntityStunStateSO stateData, PatrolEnemy enemy) : base(entity, stateMachine, animBoolName, stateData)
 {
     this._enemy = enemy;
 }
 void Start()
 {
     cc = GetComponent <PatrolEnemy>();
 }