Esempio n. 1
0
    private void Shoot()
    {
        if (target != null)
        {
            GameObject bulletInst   = (GameObject)Instantiate(bulletGo, transform.position, Quaternion.identity);
            bullet     bulletScript = bulletInst.GetComponent <bullet>();

            bulletScript.damage             = myAttributes.damage;
            bulletInst.transform.localScale = new Vector3(myAttributes.shotSize, myAttributes.shotSize, bulletInst.transform.localScale.z);

            bulletScript.ChangeDamageType(myAttributes.myDamageType);

            Rigidbody2D bulletRB = bulletInst.GetComponent <Rigidbody2D>();
            bulletRB.AddForce(transform.right * myAttributes.bulletSpeed, ForceMode2D.Impulse);
        }
    }
Esempio n. 2
0
    private void Shoot()
    {
        Vector3 bulletOffset = transform.right * 0.5f;

        GameObject bulletInst = (GameObject)Instantiate(bulletPrefab, new Vector3(transform.position.x, transform.position.y, bulletPrefab.transform.position.z) + bulletOffset, Quaternion.identity);

        Vector3 spreadVector = new Vector3(Random.Range(-spreadAmount, spreadAmount), Random.Range(-spreadAmount, spreadAmount), 0f);

        bulletInst.GetComponent <Rigidbody2D>().AddForce(transform.right * BulletMovementSpeed + spreadVector, ForceMode2D.Impulse);

        bullet bulletScript = bulletInst.GetComponent <bullet>();

        bulletScript.setIsPlayers(true);
        bulletScript.ChangeColor(playerBulletColor);
        bulletScript.ChangeDamageType(playerDamageType);

        shootTimer = fireRate + Time.time;
    }