Ejemplo n.º 1
0
    public void Fire(string owner, Vector3 firePosition, Quaternion fireRotation)
    {
        GameObject obj = NewObjectPooler.current.GetPooledObject();

        if (obj == null)
        {
            return;
        }

        obj.transform.position = firePosition;
        obj.transform.rotation = fireRotation;
        obj.transform.Translate(SpawnOffset);
        obj.SetActive(true);
        obj.GetComponent <Bullet>().owner = owner;

        //Vector2 bulletVelocity = transform.TransformDirection(Vector3.right * 100.0f);

        //Vector2 bulletVelocity = (firingDirection.normalized * bulletSpeed);
        Vector2 bulletVelocity = transform.right * bulletSpeed;

        //bulletVelocity += body2D.velocity;
        //Debug.Log(body2D.velocity);
        //obj.GetComponent<Rigidbody2D>().velocity = body2D.velocity;
        obj.GetComponent <Rigidbody2D>().AddForce(bulletVelocity);

        if (soundEffects.IsCloseToPlayer(obj.transform.position))
        {
            soundEffects.PlayOnFire();
        }
    }