コード例 #1
0
    void Shooting()
    {
        if (loaded)
        {
            Unload();
            GameObject TemporaryBullethandler;
            TemporaryBullethandler = gameObject.transform.GetChild((gameObject.transform.childCount - 1)).gameObject;
            TemporaryBullethandler.transform.parent = null;
            TemporaryBullethandler.GetComponent <Rigidbody>().useGravity       = true;
            TemporaryBullethandler.GetComponent <Rigidbody>().detectCollisions = true;
            //Instantiate(bullet,bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject;

            TemporaryBullethandler.transform.Rotate(Vector3.left * 90);

            Rigidbody TempRigidbody;
            TempRigidbody = TemporaryBullethandler.GetComponent <Rigidbody>();
            TempRigidbody.AddForce(transform.forward * (bulletSpeed + moveSpeed));
            if (bullet.name == "bullet" || bullet.name == "Bomb")
            {
                TempRigidbody.AddForce(transform.up * (250));
            }

            TemporaryBullethandler.GetComponent <Bullet>().collisionEnable = true;
            Destroy(TemporaryBullethandler, 6.0f);
            if (bulletSpeed <= 1500)
            {
                ShootSound.Play();
            }
            else if (bulletSpeed <= 2000)
            {
                UziSound.Play();
            }
            else
            {
                SniperSound.Play();
            }
        }
        else
        {
            //print("shooting is on cooldown");
            //ReloadSound.Play();
        }
    }
コード例 #2
0
ファイル: shooting02.cs プロジェクト: Mojtabaohz/TopTanksAI
    // Update is called once per frame
    void Update()
    {
        if (!shootCD)
        {
            Timer += Time.deltaTime;
            if (Timer >= shootTimer)
            {
                Timer   = 0;
                shootCD = true;
                ShootSign.GetComponent <Image>().color = Color.green;
            }
        }

        if (Input.GetButtonDown("ShootKey02"))
        {
            if (shootCD)
            {
                shootCD = false;
                ShootSign.GetComponent <Image>().color = Color.red;
                GameObject TemporaryBullethandler;
                TemporaryBullethandler = Instantiate(bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject;

                TemporaryBullethandler.transform.Rotate(Vector3.left * 90);

                Rigidbody TempRigidbody;
                TempRigidbody = TemporaryBullethandler.GetComponent <Rigidbody>();
                TempRigidbody.AddForce(transform.forward * bulletSpeed);

                Destroy(TemporaryBullethandler, 7.0f);
            }
            else
            {
                print("shooting is on cooldown");
            }
        }
    }