Exemplo n.º 1
0
    public void Shoot()
    {
        // Set the position at which the new bullet should be instantiated.
        float   widthOfSource         = gameObject.GetComponent <Renderer>().bounds.size.x;
        Vector3 instantiatingPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        GameObject newBullet = Instantiate(projectile, instantiatingPosition, transform.rotation) as GameObject;

        // Set source and target/targets of shooting to the fireball.
        FireballBehaviour bulletBehaviourScript = newBullet.GetComponent <FireballBehaviour>();
        GameObject        shootingSource        = gameObject.transform.parent.gameObject;

        bulletBehaviourScript.SetShootingSource(shootingSource);
        bulletBehaviourScript.SetShootingTarget(shootingTargets);

        // Give the bullet speed.
        Rigidbody2D rigid = newBullet.GetComponent <Rigidbody2D>();

        rigid.velocity = transform.up * 60;
    }
Exemplo n.º 2
0
    /// <summary>
    /// Shoot whenever the specific control key is pressed.
    /// </summary>
    private void Shoot()
    {
        transform.position = wisp.transform.position;
        float widthOfSource = wisp.GetComponent <Renderer>().bounds.size.x;

        Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);

        mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);

        Vector3 target = mousePosition - transform.position;

        transform.rotation = Quaternion.LookRotation(Vector3.forward, target);
        if (Input.GetMouseButtonDown(0))
        {
            AudioSource.PlayClipAtPoint(wispCharge1, transform.position);
        }
        else if (Input.GetMouseButton(0))
        {
            if (chargeTimeVariable > 0)
            {
                strengthVariable   += chargeSpeed * Time.deltaTime;
                chargeTimeVariable -= Time.deltaTime;

                AudioSource.PlayClipAtPoint(wispChargeRelease, transform.position);
            }
            else
            {
                Debug.Log("Implosion");
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            Vector3 instantiatingPosition = new Vector3(transform.position.x + (widthOfSource / 2), transform.position.y, transform.position.z);
            if (isFacingOpposite)
            {
                instantiatingPosition.x = instantiatingPosition.x - widthOfSource;
            }

            GameObject newBullet = Instantiate(fireball, instantiatingPosition, transform.rotation) as GameObject;

            // Set source and target/targets of shooting to the fireball.
            FireballBehaviour bulletBehaviourScript = newBullet.GetComponent <FireballBehaviour>();
            GameObject[]      shootingTargets       = GameObject.FindGameObjectsWithTag("Enemy");
            GameObject        shootingSource        = gameObject.transform.parent.gameObject;

            bulletBehaviourScript.SetShootingSource(shootingSource);
            bulletBehaviourScript.SetShootingTarget(shootingTargets);

            // Set the bullet's size.
            Transform fireballSize = newBullet.GetComponent <Transform>();
            fireballSize.localScale = new Vector3(0.1f * strengthVariable, 0.1f * strengthVariable, 1);

            // Give the bullet speed.
            Rigidbody2D rigidBody = newBullet.GetComponent <Rigidbody2D>();
            rigidBody.gravityScale = normalGravity;
            rigidBody.velocity     = transform.up * strengthVariable * fireballSpeed;

            strengthVariable   = strength;
            chargeTimeVariable = chargeTime;

            AudioSource.PlayClipAtPoint(wispCharge2, transform.position);
        }
    }