Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (!pause.gamepaused)
        {
            if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Alpha6))
            {
                float   step = 80f * Time.deltaTime;
                Vector3 var1 = new Vector3(0, -2.15f, 0);
                Vector3 v    = new Vector3(0, 0, 1);

                if (gun.transform.rotation.z > -0.68f)
                {
                    gun.transform.RotateAround(var1, v, -step);
                    //Debug.Log(gun.transform.rotation.eulerAngles.z);
                    if (gun.transform.rotation.z < -0.68f)
                    {
                        gun.transform.RotateAround(var1, v, step);
                    }
                }
            }
            if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Alpha4))
            {
                float   step = 80f * Time.deltaTime;
                Vector3 var1 = new Vector3(0, -2.15f, 0);
                Vector3 v    = new Vector3(0, 0, 1);
                if (gun.transform.rotation.z < 0.68f)

                {
                    gun.transform.RotateAround(var1, v, step);
                    if (gun.transform.rotation.z > 0.68f)
                    {
                        gun.transform.RotateAround(var1, v, -step);
                    }
                }
            }
            if ((Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Alpha8)) && canShoot)
            {
                canShoot = false;
                GameObject   bullet1 = Instantiate(bulletobj, gun.transform.position, gun.transform.rotation);
                bulletscript b       = bullet1.AddComponent <bulletscript>() as bulletscript;
                b.obj = bullet1;
                if (bang)
                {
                    b.bang = bang;
                }
                if (PlayerPrefs.GetInt("sound") == 1)
                {
                    firebullet.Play();
                }
                StartCoroutine(ShootDelay());
            }
            if (Score.flagStop)
            {
                Destroy(this);
            }
        }
    }
    void FireBullet()
    {
        if (!pause.gamepaused)
        {
            multibulletCount--;
            if (multibulletCount == 0)
            {
                curr_score = Score.scorecount;
            }
            bullettext.text = multibulletCount.ToString();

            GameObject   bullet1 = Instantiate(bulletobj, guntransform.position, guntransform.rotation);
            bulletscript b       = bullet1.AddComponent <bulletscript>() as bulletscript;
            b.obj = bullet1;
            // bullet1.transform.rotation.Set(guntransform.rotation.x,guntransform.rotation.y,guntransform.rotation.z + 1.0f , guntransform.rotation.w);


            Quaternion rotation = new Quaternion(guntransform.rotation.x, guntransform.rotation.y, guntransform.rotation.z + 0.3f, guntransform.rotation.w);


            GameObject   bullet2 = Instantiate(bulletobj, guntransform.position + new Vector3(0.2f, 0f, 0f), rotation);
            bulletscript b2      = bullet2.AddComponent <bulletscript>() as bulletscript;
            b2.obj = bullet2;
            //bullet2.transform.rotation.Set(guntransform.rotation.x, guntransform.rotation.y, guntransform.rotation.z + 3.0f, guntransform.rotation.w);


            rotation = new Quaternion(guntransform.rotation.x, guntransform.rotation.y, guntransform.rotation.z + 0.6f, guntransform.rotation.w);



            GameObject   bullet3 = Instantiate(bulletobj, guntransform.position + new Vector3(0.4f, 0f, 0f), rotation);
            bulletscript b3      = bullet3.AddComponent <bulletscript>() as bulletscript;
            b3.obj = bullet3;

            rotation = new Quaternion(guntransform.rotation.x, guntransform.rotation.y, guntransform.rotation.z - 0.3f, guntransform.rotation.w);


            GameObject   bullet4 = Instantiate(bulletobj, guntransform.position + new Vector3(-0.2f, 0f, 0f), rotation);
            bulletscript b4      = bullet4.AddComponent <bulletscript>() as bulletscript;
            b4.obj = bullet4;

            rotation = new Quaternion(guntransform.rotation.x, guntransform.rotation.y, guntransform.rotation.z - 0.6f, guntransform.rotation.w);


            GameObject   bullet5 = Instantiate(bulletobj, guntransform.position + new Vector3(-0.4f, 0f, 0f), rotation);
            bulletscript b5      = bullet5.AddComponent <bulletscript>() as bulletscript;
            b5.obj = bullet5;
        }
    }
Beispiel #3
0
 void Start()
 {
     reloadTimer        = 0;
     bulletsUI          = ammoUI.transform.GetChild(0).GetComponent <UnityEngine.UI.Text>();
     magsUI             = ammoUI.transform.GetChild(1).GetComponent <UnityEngine.UI.Text>();
     reloadUI           = ammoUI.transform.GetChild(2).GetComponent <UnityEngine.UI.Text>();
     reloadBarContainer = ammoUI.transform.GetChild(3).gameObject;
     reloadBar          = reloadBarContainer.transform.GetChild(0).GetComponent <RectTransform>();
     nextFire           = 0.0f;
     reallyWeakGun      = new Gun(7, 20, 20, 7, 10, 1, 5, 72, 24, 2, 2);
     weakGun            = new Gun(10, 10, 20, 13, 5, 1, 5, 72, 24, 2, 2);
     machinegun         = new Gun(15, 5, 30, 19, 3, 1, 5, 72, 64, 3, 1);
     pistol             = new Gun(100, 10, 100, 10, 100, 5, 10, 2000, 100, 5, 1);
     equipped           = reallyWeakGun;
     bs             = bullet.GetComponent <bulletscript>();
     bulletPool     = new Stack <GameObject>();
     bulletsUI.text = equipped.magazine.ToString();
     magsUI.text    = equipped.Ammo.ToString();
 }
Beispiel #4
0
    void spawnBullet()
    {
        Vector3    spawnposition = transform.position;
        GameObject spawnObject   = null;

        if (shootvertical)
        {
            if (shootpositive)
            {
                spawnposition.y += 0.5f;
            }
            else
            {
                spawnposition.y -= 0.5f;
            }
        }
        else
        {
            if (shootpositive)
            {
                spawnposition.x += 0.5f;
            }
            else
            {
                spawnposition.x -= 0.5f;
            }
        }
        if (posion)
        {
            spawnObject = (GameObject)Instantiate(Resources.Load("bullets"), spawnposition, Quaternion.identity);
        }
        else if (water)
        {
            spawnObject = (GameObject)Instantiate(Resources.Load("WaterBullet"), spawnposition, Quaternion.identity);
        }
        //Debug.Log("Spawn bullet "+ Time.time.ToString());
        bulletscript bullet = (bulletscript)spawnObject.GetComponent("bulletscript");

        bullet.positive = shootpositive;
        bullet.vertical = shootvertical;
        bullet.speed    = bulletspeed;
    }