Пример #1
0
 // Use this for initialization
 void Start()
 {
     _control = GetComponentInChildren<BulletControl>();
     _effect = GetComponentInChildren<BulletEffectBase>();
     if (_control == null || _effect == null)
         Debug.LogError("Bullet don't set");
 }
Пример #2
0
    /// <summary>
    /// Fire the gun if clicking.
    /// </summary>
    private void FireGun()
    {
        // do nothing if not currently firing
        if (!Input.GetMouseButtonDown(0) || RemainFireTime > 0.0f)
        {
            return;
        }

        // reset the cooldown timer
        RemainFireTime = FireCooldown;

        // determine direction towards mouse
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 direction     = mousePosition - transform.position;

        if (direction != Vector3.zero)
        {
            direction.Normalize();
        }

        // fire bullet towards direction
        GameObject    obj    = Instantiate <GameObject>(Bullet);
        BulletControl bullet = obj.GetComponent <BulletControl>();

        bullet.transform.localPosition = GunEnd.transform.position;
        bullet.MoveDirection           = direction;
    }
    public void UseWeapon()
    {
        if (BulletObj != null)
        {
            BulletControl bulletInstance = Instantiate(BulletObj, transform.position, Quaternion.Euler(new Vector3(0, 0, 1))).GetComponent <BulletControl>();
            bulletInstance.Ignore = BulletIgnores;
            bulletInstance.power  = Power;
            Vector2 dir = Vector2.right;
            if (!FacingRightCallback())
            {
                dir *= -1;
            }
            if (bulletInstance != null)
            {
                bulletInstance.SetDirection(dir);
            }


            //if (bulletBody != null) {
            //    bulletBody.velocity = transform.forward * bulletInstance.Spe;

            //    Physics2D.IgnoreCollision(bulletInstance.GetComponent<Collider2D>(), GetComponent<Collider2D>());
            //}
        }
    }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (fireInTheRole > 0)
     {
         BulletControl newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
         newBullet.speed = bullletSpeed;
         fireInTheRole--;
     }
 }
Пример #5
0
    public void LuncherBulletBall()
    {
        GameObject go = Instantiate(_preBullet);

        go.transform.position = _tfMagicPosition.position;
        go.transform.rotation = _tfMagicPosition.rotation;
        BulletControl bull = go.GetComponent <BulletControl>();

        bull.InitDamage(this);
    }
Пример #6
0
    public GameObject FireBullet(Vector3 pos, Vector3 des)
    {
        pos.y = 1.68f;
        GameObject bullet = Instantiate(Resources.Load("MyPrefabs/Shell", typeof(GameObject)), pos, Quaternion.identity, null) as GameObject;

        bullet.transform.forward = des;
        BulletControl bulletScript = bullet.gameObject.AddComponent <BulletControl>() as BulletControl;

        bulletList.Add(bullet);
        return(bullet);
    }
 internal static void Bullet_Hurt(TriggerInfo triggerInfo)
 {
     MainThread.Run(() =>
     {
         GameObject Bullet           = GameObject.Instantiate(Info.ParticleInfo.Instance.HurtBullet);
         BulletControl bulletControl = Bullet.GetComponent <BulletControl>();
         bulletControl.Init(triggerInfo.triggerCard, triggerInfo.targetCard);
         bulletControl.Play();
         Bullet.GetComponent <ParticleSystem>().Play();
     });
 }
Пример #8
0
    void Start()
    {
        line = GetComponent <LineDrawControl>();
        au   = GetComponent <AudioSource>();

        layerMask       = LayerMask.GetMask("Wall");
        cw              = HMD.GetComponent <CameraWork>();
        cw.OnFollowEnd += CameraWorkEnd;

        BC = bullet.GetComponent <BulletControl>();

        transform.rotation = Quaternion.Euler(startRotation);
    }
Пример #9
0
    private void PlayerShoot()
    {
        GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);

        SpriteRenderer bulletSR = bullet.GetComponent <SpriteRenderer>();

        bulletSR.sprite = playerEquipment.bullet.bulletSprite;

        Rigidbody2D bulletRB = bullet.GetComponent <Rigidbody2D>();

        bulletRB.AddForce(Vector2.up * playerEquipment.bulletSpeed, ForceMode2D.Impulse);

        BulletControl bulletControl = bullet.GetComponent <BulletControl>();
        var           damage        = playerEquipment.bulletDamage;

        bulletControl.bulletDamage = damage;
    }
Пример #10
0
 // Update is called once per frame
 void Update()
 {
     if (isFiring)
     {
         mShotCounter -= Time.deltaTime;
         if (mShotCounter <= 0.0f)
         {
             print("firing");
             mShotCounter = timeBetweenShots;
             BulletControl tempBullet = Instantiate(bullet, muzzleTransform.position, muzzleTransform.rotation);
             tempBullet.speed = bulletSpeed;
         }
     }
     else
     {
         mShotCounter = 0.0f;
     }
 }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        // aiming
        GameObject enemy = TurretUtilities.GetTargetedEnemy(gameObject, range);

        if (enemy != null)
        {
            Utilities.LookAt2D(gameObject.transform, enemy.transform);

            // shooting
            if (Time.time - timeOfLastShot > shotInterval)
            {
                timeOfLastShot = Time.time;
                GameObject bullet = Instantiate(Bullet, transform.position, transform.rotation) as GameObject;

                BulletControl bulletControl = bullet.GetComponent("BulletControl") as BulletControl;
                bulletControl.Range  = range;
                bulletControl.Speed  = bulletSpeed;
                bulletControl.Damage = bulletDamage;
            }
        }
    }
    private void SpawnBullet(string side)
    {
        if (side == "Right")
        {
            var           b       = Instantiate(bulletPrefab, bulletSpawnRight.position, Quaternion.identity);
            BulletControl bScript = b.GetComponent <BulletControl>();
            bScript.target = boss;
        }

        else if (side == "Left")
        {
            var           b       = Instantiate(bulletPrefab, bulletSpawnLeft.position, Quaternion.identity);
            BulletControl bScript = b.GetComponent <BulletControl>();
            bScript.target = boss;
        }

        source.clip = shotClip;
        if (!source.isPlaying)
        {
            source.Play();
        }

        Debug.Log("Bullet Spawned");
    }
Пример #13
0
 // Start is called before the first frame update
 private void Awake()
 {
     _uniqueInstance = this;
     _rgd3D          = GetComponent <Rigidbody>();
 }
Пример #14
0
 private void Awake()
 {
     bullet = FindObjectOfType <BulletControl>();
 }
Пример #15
0
 public void SetBulletControl(BulletControl controlBase)
 {
     bulletControl = controlBase;
 }
Пример #16
0
    // Update is called once per frame
    void Update()
    {
        float move_X = Input.GetAxisRaw("Horizontal"); //控制水平移动方向 A:-1 D:1 0
        float move_Y = Input.GetAxisRaw("Vertical");   //控制垂直移动方向 W:1 S:-1 0


        Vector2 moveVector = new Vector2(move_X, move_Y);

        if (moveVector.x != 0 || moveVector.y != 0)
        {
            lookDirectiion = moveVector;
        }
        anim.SetFloat("Look X", lookDirectiion.x);
        anim.SetFloat("Look Y", lookDirectiion.y);
        anim.SetFloat("Speed", moveVector.magnitude);



        //================移动================================
        Vector2 position = rbody.position;

        //position.x += move_X * speed * Time.deltaTime;
        //position.y += move_Y * speed * Time.deltaTime;
        position += moveVector * speed * Time.deltaTime;


        rbody.MovePosition(position);

        //================无敌计时============================
        if (isInvincible)
        {
            invincibleTimer -= Time.deltaTime;
            if (invincibleTimer < 0)
            {
                isInvincible = false;//倒计时结束之后(2秒),取消无敌状态
            }
        }
        //================按下j键并且子弹数量大于0进行攻击===========
        if (Input.GetKeyDown(KeyCode.J) && curBulletCount > 0)
        {
            ChangeBulletCount(-1);                       //每次攻击减1个子弹
            anim.SetTrigger("Launch");                   //播放攻击动画
            AudioManager.Instance.AudioPlay(launchClip); //播放攻击音效
            GameObject    bullet = Instantiate(bulletPrefab, rbody.position + Vector2.up * 0.5f, Quaternion.identity);
            BulletControl bc     = bullet.GetComponent <BulletControl>();
            if (bc != null)
            {
                bc.Move(lookDirectiion, 300);
            }
        }
        //================按下E键,进行NPC交互
        if (Input.GetKeyDown(KeyCode.E))
        {
            RaycastHit2D hit = Physics2D.Raycast(rbody.position, lookDirectiion, 2f, LayerMask.GetMask("npc"));
            if (hit.collider != null)
            {
                NPCManager npc = hit.collider.GetComponent <NPCManager>();
                if (npc != null)
                {
                    npc.showDialog();
                }
            }
        }
    }