Inheritance: MonoBehaviour
示例#1
0
 void onShoot()
 {
     if (!isDie)
     {
         EnemyBulletScript.Create(transform, direction);
     }
 }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        //A different way of finding the player.  Keeping it just in case.
        //  Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, 20);
        //  int i = 0;
        //  while (i < hitColliders.Length)
        //  {
        //      if (hitColliders[i].CompareTag("Player"))
        //          player = hitColliders[i].gameObject;
        //      i++;
        //  }
        if (hp <= 0)
        {
            Destroy(this.gameObject);
        }
        if (waitTime > 0)
        {
            waitTime--;
        }
        else
        {
            Vector3           myPos      = new Vector3(transform.position.x, transform.position.y, 0);
            EnemyBulletScript projectile = Instantiate(obj, myPos, Quaternion.identity);
            projectile.setTarget(player);
            waitTime = interval;
        }
        Vector3 playerPos = new Vector3(player.transform.position.x, player.transform.position.y, 0);
        Vector3 direction = (playerPos - GetComponent <Rigidbody2D>().transform.position);

        direction.z = 0;
        direction.Normalize();
        GetComponent <Rigidbody2D>().velocity = direction * moveSpeed;
    }
示例#3
0
    public static EnemyBulletScript Create(Transform _parent, Consts.MoveDirection _moveDirection)
    {
        GameObject        pre    = Resources.Load("Prefabs/Game/EnemyBullet", typeof(GameObject)) as GameObject;
        GameObject        bullet = GameObject.Instantiate(pre, BgScript.s_instance.map);
        EnemyBulletScript script = bullet.GetComponent <EnemyBulletScript>();

        script.setData(_parent, _moveDirection);
        return(script);
    }
示例#4
0
 void Update()
 {
     if (enemyguntrigger == true)
     {
         Debug.Log("enemy shooting gun1");
         Randomgun = Random.Range(1, 4);
         if (Randomgun == 1)
         {
             Shots -= Time.deltaTime;
             if (Shots <= 0)
             {
                 Shots = Shotstimer;
                 EnemyBulletScript enemybullet = Instantiate(EnemyBullet, EnemyBulletLocation.position, EnemyBulletLocation.rotation) as EnemyBulletScript;
                 enemybullet.enemybulletSpeed = bulletspeed;
             }
         }
         if (Randomgun == 2)
         {
             Shots -= Time.deltaTime;
             if (Shots <= 0)
             {
                 Shots = Shotstimer;
                 EnemyBulletScript enemybullet2 = Instantiate(EnemyBullet2, EnemyBulletLocation.position, EnemyBulletLocation.rotation) as EnemyBulletScript;
                 enemybullet2.enemybulletSpeed = bulletspeed;
             }
         }
         if (Randomgun == 3)
         {
             Shots -= Time.deltaTime;
             if (Shots <= 0)
             {
                 Shots = Shotstimer;
                 EnemyBulletScript enemybullet3 = Instantiate(EnemyBullet3, EnemyBulletLocation.position, EnemyBulletLocation.rotation) as EnemyBulletScript;
                 enemybullet3.enemybulletSpeed = bulletspeed;
             }
         }
     }
     else
     {
         Shots = 0;
     }
     //if (enemygun3trigger == true)
     //{
     //    Debug.Log("enemy shooting gun3");
     //    Shots -= Time.deltaTime;
     //    if (Shots <= 0)
     //    {
     //        Shots = Shotstimer;
     //        EnemyBulletScript enemybullet = Instantiate(EnemyBullet, EnemyBulletLocation.position, EnemyBulletLocation.rotation) as EnemyBulletScript;
     //        enemybullet.enemybulletSpeed = bulletspeed;
     //    }
     //}
     //else
     //{
     //    Shots = 0;
     //}
 }
示例#5
0
    public void Shoot(float Dmg, string PlayerTeg, Vector2 vector)
    {
        EnemyBulletScript bullet = Instantiate(bulletPrefab); // создается копия пули на сцене.

        bullet.transform.position = ShootPos.position;        // пулю ставят в позицию Shooter
        bullet.Damage             = Dmg;
        bullet.TargetTag          = PlayerTeg;


        bullet.GetComponent <Rigidbody2D>().AddForce(vector * shootForce);
        Destroy(bullet.gameObject, BulletDestroyTime);
    }
    /// <summary>
    /// 탄환을 발사합니다.
    /// </summary>
    /// <param name="shotPosition">탄환을 발사할 위치입니다.</param>
    public void Shot(Transform shotPosition)
    {
        SoundEffects[1].Play();
        Instantiate(effects[1], shotPosition.position, shotPosition.rotation);

        //
        EnemyBulletScript bullet = Instantiate
                                       (_bullet, shotPosition.position, shotPosition.rotation)
                                   as EnemyBulletScript;

        bullet.transform.parent = _StageManager._enemyParent.transform;
        bullet.MoveTo(FacingRight ? Vector3.right : Vector3.left);
    }
示例#7
0
 void Shot()
 {
     bullettimer += Time.deltaTime;
     if (bullettimer > bullettime)
     {
         direction = (Player.transform.position - this.transform.position).normalized;
         GameObject bulletcopy = Instantiate(bullet, this.transform.position + 2 * direction, Quaternion.LookRotation(direction));
         bulletscript             = bulletcopy.GetComponent <EnemyBulletScript>();
         bulletscript.playercs    = playerscript;
         bulletscript.bulletpower = bulletcopypower;
         bulletscript.bulletspeed = bulletcopyspeed;
         bullettimer = 0;
     }
 }
示例#8
0
    void ShotBullet(Transform shotPostion, Vector3 player)
    {
        //  GameObject shoteff = Instantiate(shotEffect, shotPos[0].position, shotPos[0].rotation);
        //if(isSeeRight)
        //{
        //    Vector3 localScale = shoteff.transform.localScale;
        //    shoteff.transform.localScale = new Vector3(-localScale.x, localScale.y);
        //}

        EnemyBulletScript bullet = Instantiate(enemyBullet, shotPostion.position, shotPostion.rotation) as EnemyBulletScript;

        bullet.isSeeRight = isSeeRight;
        bullet.MoveToPlayer(player);
    }
示例#9
0
 void fire(Vector3 target)
 {
     if (lastfire <= 0)
     {
         Vector3           dir         = target - (transform.position);
         Transform         b           = Network.Instantiate(bullet, transform.position, transform.rotation, 0) as Transform;
         EnemyBulletScript enemybullet = b.GetComponent("EnemyBulletScript") as EnemyBulletScript;
         enemybullet.ad = ad;
         enemybullet.sd = sd;
         dir.Normalize();
         b.rigidbody.AddForce(dir * force);
         lastfire = FIRETIME;
     }
 }
示例#10
0
    public void Shot()
    {
        GameObject        Shot_effect  = Instantiate(ShotEffect, shotPos.position, shotPos.rotation);
        EnemyBulletScript enemy_Bullet = Instantiate(bullet, shotPos.position, shotPos.rotation) as EnemyBulletScript;

        if (isSeeRight)
        {
            Vector2 localScale = Shot_effect.transform.localScale;
            Shot_effect.transform.localScale = new Vector2(-localScale.x, localScale.y);
        }
        //   enemy_Bullet = Instantiate(bullet, shotPos.position, shotPos.rotation);
        bullet.isSeeRight = isSeeRight;

        enemy_Bullet.MoveToPlayer(player.gameObject.transform.position);
    }
示例#11
0
 void fire(Vector3 target)
 {
     if (lastfire <= 0)
     {
         // they have to aim at you to shoot but this code lets them shoot up and down at you too
         Vector3 dir = target - (gun.position + gun.forward * 3f);
         if (Vector3.Angle(gun.forward, dir) <= 10)
         {
             Transform         b           = Network.Instantiate(bullet, gun.position + transform.forward * 3f, transform.rotation, 0) as Transform;
             EnemyBulletScript enemybullet = b.GetComponent("EnemyBulletScript") as EnemyBulletScript;
             enemybullet.ad = ad;
             enemybullet.sd = sd;
             dir.Normalize();
             b.rigidbody.AddForce(gun.forward * force);
             lastfire = FIRETIME;
         }
     }
 }
    /// <summary>
    /// 탄환을 발사합니다.
    /// </summary>
    /// <param name="shotPosition">탄환을 발사할 위치입니다.</param>
    /// <param name="destination">탄환의 목적지입니다.</param>
    public void Shot(Transform shotPosition, Vector3 destination)
    {
        SoundEffects[1].Play();
        GameObject effect = Instantiate(effects[1], shotPosition.position, shotPosition.rotation);

        if (FacingRight)
        {
            Vector3 scale = effect.transform.localScale;
            effect.transform.localScale = new Vector3(-scale.x, scale.y);
        }

        //
        EnemyBulletScript bullet = Instantiate
                                       (_bullets[0], shotPosition.position, shotPosition.rotation)
                                   as EnemyBulletScript;

        bullet.transform.parent = _StageManager._enemyParent.transform;

        //
        bullet.FacingRight = FacingRight;
        bullet.MoveTo(destination);
    }
示例#13
0
    /// <summary>
    /// 탄환을 발사합니다.
    /// </summary>
    /// <param name="shotPosition">탄환을 발사할 위치입니다.</param>
    public void Shot(Transform shotPosition)
    {
        SoundEffects[1].Play();
        GameObject effect = Instantiate
                                (effects[1], shotPosition.position, shotPosition.rotation);

        if (FacingRight)
        {
            Vector3 scale = effect.transform.localScale;
            effect.transform.localScale = new Vector3(-scale.x, scale.y);
        }

        // 탄환을 생성합니다.
        EnemyBulletScript bullet = Instantiate
                                       (_bullet, shotPosition.position, shotPosition.rotation)
                                   as EnemyBulletScript;

        bullet.transform.parent = _StageManager._enemyParent.transform;

        // 플레이어의 위치를 향해 발사합니다.
        bullet.FacingRight = FacingRight;
        bullet.MoveTo(StageManager.Instance.GetCurrentPlayerPosition());
    }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        body.SetBool("Left", lookLeft);
        body.SetBool("Right", lookRight);

        // HealthScript

        health    = healthScript.health;
        shield    = healthScript.shield;
        maxHealth = healthScript.maxHealth;
        maxShield = healthScript.maxShield;

        // Patrolling back and forth
        transform.Translate(new Vector3(moveSpeed, 0, 0) * Time.deltaTime * direction);

        if (Time.time > patrolTime + lastSwitch)
        {
            direction *= -1;
            lastSwitch = Time.time;
        }

        // Flipping legs based on direction
        if (direction == -1)
        {
            legsOb.localScale = new Vector3(-1, 1, 1);
        }
        if (direction == 1)
        {
            legsOb.localScale = new Vector3(1, 1, 1);
        }

        // Looking left and right
        if (player.transform.position.x < bodyOb.transform.position.x &&
            player.transform.position.x > bodyOb.transform.position.x - range &&
            fireMode == false)
        {
            aimDirection = -1;
            lookLeft     = true;
            lookRight    = false;
        }
        if (player.transform.position.x > bodyOb.transform.position.x &&
            player.transform.position.x < bodyOb.transform.position.x + range &&
            fireMode == false)
        {
            aimDirection = 1;
            lookRight    = true;
            lookLeft     = false;
        }

        // In and out of range
        if ((bodyOb.transform.position.y - 4) < player.transform.position.y &&
            player.transform.position.y < (bodyOb.transform.position.y + 4))
        {
            if (player.transform.position.x < bodyOb.transform.position.x &&
                player.transform.position.x > bodyOb.transform.position.x - range)
            {
                // Firing left
                if (readyToFire)
                {
                    enterRange  = Time.time;
                    lastShot    = Time.time + fireDelay;
                    bulletCount = 0;
                    fireMode    = true;
                    readyToFire = false;
                }
            }
            else if (player.transform.position.x > bodyOb.transform.position.x &&
                     player.transform.position.x < bodyOb.transform.position.x + range)
            {
                // Firing right
                if (readyToFire)
                {
                    enterRange  = Time.time;
                    lastShot    = Time.time + fireDelay;
                    bulletCount = 0;
                    fireMode    = true;
                    readyToFire = false;
                }
            }
        }

        // Firing
        if (fireMode)
        {
            if (Time.time > lastShot + fireRate &&
                bulletCount < 2)
            {
                if (aimDirection == -1)
                {
                    GameObject bullet = Instantiate(buzzerBullet, firePointLeft.transform.position,
                                                    Quaternion.Euler(0f, 0f, 180f));
                    EnemyBulletScript bScript = bullet.GetComponent <EnemyBulletScript>();
                    bScript.damage         = damage;
                    bScript.headshotDamage = damage;
                    bScript.velocity       = bulletVelocity;
                    bScript.bulletLife     = bulletLife;
                    lastShot = Time.time;
                    bulletCount++;
                }
                if (aimDirection == 1)
                {
                    GameObject bullet = Instantiate(buzzerBullet, firePointRight.transform.position,
                                                    Quaternion.Euler(0f, 0f, 0f));
                    EnemyBulletScript bScript = bullet.GetComponent <EnemyBulletScript>();
                    bScript.damage         = damage;
                    bScript.headshotDamage = damage;
                    bScript.velocity       = bulletVelocity;
                    bScript.bulletLife     = bulletLife;
                    lastShot = Time.time;
                    bulletCount++;
                }
            }
            if (Time.time > enterRange + 5)
            {
                readyToFire = true;
                fireMode    = false;
                bulletCount = 0;
            }
        }

        // Health/Shield Bars
        healthScale = health / maxHealth;
        shieldScale = shield / maxShield;

        healthBar.transform.localScale = new Vector3(healthScale, 1, 1);
        shieldBar.transform.localScale = new Vector3(shieldScale, 1, 1);

        // Health
        if (health <= 0)
        {
            Destroy(gameObject);
        }
    }