示例#1
0
    // Fires a bullet in a random direction.
    private void RandomBullet(float speed)
    {
        Quaternion quat = Random.rotation;
        Bullet     p    = bullets.CreateBullet(transform, transform, 20.0f);

        p.transform.rotation = Quaternion.RotateTowards(p.transform.rotation, quat, 360.0f);
        p.SetSpeed(speed);
        p.gameObject.layer = 15;
    }
示例#2
0
    public void StartShooting()
    {
        var bullet = BulletPool.CreateBullet(_spawnPoint);

        bullet.Move();
        _fireParticleSystem.Play();
    }
示例#3
0
    protected Bullet CreateBullet(Transform t)
    {
        Bullet bullet = bulletPool.CreateBullet(t, t, 2.0f);

        bullet.ChangeFacing(pc.FacingDir);
        bullet.gun = this;
        bullet.gameObject.layer = 11;
        return(bullet);
    }
示例#4
0
    public void Shoot(Transform transform, Transform target)
    {
        timeStamp -= Time.deltaTime;

        if (timeStamp <= 0.0f)
        {
            timeStamp = timeBetweenShots;
            Bullet  bullet = bullets.CreateBullet(transform, transform, 2.0f);
            Vector3 dir    = (target.position - transform.position).normalized;
            bullet.transform.rotation = Utils.LookX(dir);
            bullet.SetSpeed(bulletSpeed);
            bullet.gameObject.layer = 15;
        }
    }
示例#5
0
    public void Shoot(Transform transform, Transform target)
    {
        timeStamp -= Time.deltaTime;

        if (timeStamp <= 0.0f)
        {
            Quaternion rot = Random.rotation;
            Bullet     p   = bullets.CreateBullet(transform, transform, 2.0f);
            Vector3    dir = (target.position - transform.position).normalized;
            p.transform.rotation = Utils.LookX(dir);
            p.transform.rotation = Quaternion.RotateTowards(p.transform.rotation, rot, spreadAngle);
            p.SetSpeed(bulletSpeed);
            p.gameObject.layer = 15;
            timeStamp          = timeBetweenShots;
        }
    }
    void Update()
    {
        Vector3 currentPos = this.transform.position;

        float xMove = Input.GetAxis("Horizontal");
        float yMove = Input.GetAxis("Vertical");

        if (xMove > 0)
        {
            this.transform.localEulerAngles = new Vector3(0, -25, 0);
        }
        else if (xMove < 0)
        {
            this.transform.localEulerAngles = new Vector3(0, 25, 0);
        }
        else
        {
            this.transform.localEulerAngles = new Vector3(0, 0, 0);
        }

        Vector3 move = new Vector3(xMove, yMove);

        move.Normalize();

        currentPos += move * speed * Time.deltaTime;

        if (!canShoot)
        {
            timeSinceShot += Time.deltaTime;
        }

        if (timeSinceShot >= shootDelay)
        {
            //timeSinceShot -= shootDelay;
            timeSinceShot = 0;
            canShoot      = true;
        }

        if (Input.GetButton("Fire1") && canShoot)
        {
            bulletPool.CreateBullet(bulletSpawn.position);

            canShoot = false;
        }

        this.transform.position = currentPos;
    }