Ejemplo n.º 1
0
    void sendRay()
    {
        Vector3 mousePos = Input.mousePosition;

        mousePos.z = 20f;
        Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos);

        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        Debug.DrawRay(ray.origin, ray.direction * 100, Color.green, 5, false);

        if (Physics.Raycast(Camera.main.transform.position, (mousePos3D - Camera.main.transform.position), out hit, 100f))
        {
            //Debug.Log(hit.collider.gameObject.name);
            //Debug.Log("衝突位置 : "+hit.point);

            //ここでストレートを打つ
            //hit.collider.gameObjectでぶつかったオブジェクトのことを指す
            Vector3 array = (hit.point - Camera.main.transform.position).normalized;

            Straight straight = new Straight();
            straight.Velocity    = 10f; // 仮の値
            straight.AttackPoint = 1;   // 仮の値
            straight.Direction   = array;
            GameObject bullet = bulletPool.GetInstance(straight);
            bullet.transform.position = this.transform.position;
            GameObject effect = bullet.transform.GetChild(0).gameObject;
            effect.GetComponent <Renderer>().material.SetColor("_EmissionColor", _straightColor);
            bullet.GetComponent <BulletObject>().Force = Force.Player;
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         _bullet = BulletPool.GetInstance(new Homing());
         Homing homing = _bullet.GetComponent <BulletObject>().bulletclass as Homing;
         homing.Velocity       = 6f;
         homing.HomingStrength = 1f;
         homing.Target         = GameObject.Find("Target");
         homing.AttackPoint    = 10;
         homing.Direction      = new Vector3(0, 0, 1);
         particleColor         = _homingColor;
         Generate();
     }
     else if (Input.GetKeyDown(KeyCode.LeftShift))
     {
         _bullet = BulletPool.GetInstance(new Straight());
         Straight straight = _bullet.GetComponent <BulletObject>().bulletclass as Straight;
         straight.Velocity    = 12f + Random.Range(-4f, 4f);
         straight.AttackPoint = 10;
         straight.Direction   = Vector3.Normalize(GameObject.Find("Target").transform.position - this.transform.position);
         particleColor        = _straightColor;
         Generate();
     }
 }
Ejemplo n.º 3
0
 private void DeactivateAndEnqueue()
 {
     if (BulletPool.GetInstance() != null)
     {
         BulletPool.GetInstance().Enqueue(this);
     }
 }
Ejemplo n.º 4
0
    public void ShootHelix()
    {
        // Increment timer
        t_rotateToPosition += Time.deltaTime;

        // rotate to position
        if (t_rotateToPosition <= 2)
        {
            transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 90, 0), Time.deltaTime);
        }
        else // Fire helix shot
        {
            // hot dog roll the ship
            transform.Rotate(Time.deltaTime * 300, 0, 0);
            if (t_fireRate > fireRate)
            {
                foreach (var e in emitters)
                {
                    GameObject bulletInst = BulletPool.GetInstance().GetBullet_Boss();

                    AudioManager.GetInstance().PlaySoundOnce(AudioManager.Sound.EnemyFire2, AudioManager.Priority.Low, transform);

                    bulletInst.SetActive(true);
                    bulletInst.transform.position = e.transform.position;
                    bulletInst.transform.LookAt(player.transform.position);
                    t_fireRate = 0;
                }
            }
        }
    }
Ejemplo n.º 5
0
Archivo: Gun.cs Proyecto: radmars/ld40
    public void Shoot()
    {
        rateOfFire = 2f * Mathf.Pow(.85f, (WaveSpawner.currentLevel - 1));

        if (this.Mover.finishedRoute)
        {
            this.gameObject.SetActive(false);
        }

        if (bulletPool == null)
        {
            bulletPool = GameObject.FindObjectOfType <BulletPool>();
        }

        var bullet = bulletPool.GetInstance(bulletPrefab);

        bullet.transform.position = transform.position;
        // TODO: Should probably inject different logics here, for now shoot straight at our hero.
        if (target)
        {
            bullet.direction = (target.transform.position - bullet.transform.position).normalized;
        }
        else
        {
            bullet.direction = -(Vector3.up);
        }

        audioSource.pitch = Random.Range(0.95f, 1.05f);
        audioSource.Play();
    }
Ejemplo n.º 6
0
        private void ShootBullet()
        {
            // De-pool the bullet and apply velocity to it.
            Bullet bullet = BulletPool.GetInstance().Dequeue();

            bullet.transform.position       = barrelEnd.position;
            bullet.BulletRigidBody.velocity = barrelEnd.forward * bulletSpeed;
        }
Ejemplo n.º 7
0
    public void Shoot()
    {
        if (bulletPool == null)
        {
            bulletPool = GameObject.FindObjectOfType <BulletPool>();
        }

        if (bulletWaveCurrent >= bulletWaveMax * 1.5f)
        {
            bulletWaveCurrent = 0;
            bulletFocus       = !bulletFocus;
        }
        else if (bulletWaveCurrent >= bulletWaveMax)
        {
            bulletWaveCurrent++;
            return;
        }

        var bullet = bulletPool.GetInstance(bulletPrefab);

        bullet.transform.position = transform.position;

        if (target)
        {
            if (bulletFocus)
            {
                bullet.direction = (target.transform.position - bullet.transform.position).normalized;
            }
            else
            {
                double progress = (double)(bulletWaveCurrent) / (double)(bulletWaveMax);
                bullet.direction = new Vector3((float)Math.Sin(progress * sineScaler * Math.PI), (float)Math.Cos(progress * sineScaler2 - 1.0f * Math.PI), 0);
            }
        }
        else
        {
            bullet.direction = -(Vector3.up);
        }

        shootSound.pitch = UnityEngine.Random.Range(0.55f, 0.75f);
        shootSound.Play();
        bulletWaveCurrent++;
    }
Ejemplo n.º 8
0
    void OnEnable()
    {
        bulletPool = BulletPool.GetInstance();
        BossEntrance();

        bossLaser = GameObject.Find("BossLaser").GetComponent <VolumetricLineBehavior>();

        if (GameObject.Find("[CameraRig]").transform.Find("Controller (right)").childCount > 1)
        {
            player = GameObject.Find("[CameraRig]").transform.Find("Controller (right)").transform.Find("Spaceship").transform;
        }
        else
        {
            player = GameObject.Find("[CameraRig]").transform.Find("Controller (left)").transform.Find("Spaceship").transform;
        }


        InvokeRepeating("Attack", 0, attackDuration);

        maxHealth = health;
    }
Ejemplo n.º 9
0
    public void ShootNormal()
    {
        lookAtTranformTest.LookAt(player.transform.position);
        lookAtTranformTest.Rotate(new Vector3(0, -90, -110));

        transform.rotation = Quaternion.Lerp(transform.rotation, lookAtTranformTest.rotation, Time.deltaTime * 2f);
        if (t_fireRate > fireRate)
        {
            foreach (var e in emitters)
            {
                //GameObject bulletInst = bulletPool.GetBullet_Boss();
                GameObject bulletInst = BulletPool.GetInstance().GetBullet_Boss();

                AudioManager.GetInstance().PlaySoundOnce(AudioManager.Sound.EnemyFire3, AudioManager.Priority.Low, transform);

                bulletInst.SetActive(true);
                bulletInst.transform.position = e.transform.position;
                bulletInst.transform.LookAt(player.transform.position);
                t_fireRate = 0;
            }
        }
    }
Ejemplo n.º 10
0
 private void Start()
 {
     bp = BulletPool.GetInstance();
 }