Exemple #1
0
    void Shot()
    {
        //弾がなければ撃てない
        if (bulletHolder.GetBulletAmount() <= 0)
        {
            audioSource.PlayOneShot(sounds[2]);
            return;
        }

        //弾の生成
        GameObject bullet = Instantiate(
            bulletPrefab,
            transform.position,
            Quaternion.identity
            );

        //生成したbulletの親をBulletHolderに設定
        bullet.transform.parent = bulletHolder.transform;

        //弾の発射
        Rigidbody bulletRigidbody = bullet.GetComponent <Rigidbody>();

        bulletRigidbody.AddForce(transform.forward * shotSpeed);
        audioSource.PlayOneShot(sounds[0]);

        bulletHolder.ConsumeBullet(); //弾の消費

        Destroy(bullet, 5f);          //指定時間後に弾消去
    }
Exemple #2
0
    /*void Damage(){
     *      HP -= 1;
     *      print (HP);
     * }*/



    void Shot()
    {
        if (bulletHolder.GetBulletAmount() <= 0)
        {
            return;
        }

        /*if (shotPower <= 0)
         *      return;*/
        /*Ray ray = new Ray(transform.position, transform.forward);
         * if (Physics.Raycast (transform.position, Vector3.forward, out hit)) {
         *
         *      Debug.Log (hit.point);
         *      Debug.DrawRay(ray.origin, ray.direction, Color.red, 3.0f);
         * }
         *
         * GameObject effectObj = Resources.Load<GameObject> ("Effects/shotEffect");
         * GameObject effect = Instantiate(effectObj, gameObject.transform.position, effectObj.transform.rotation);
         * effect.transform.parent = gameObject.transform;
         *
         * GameObject bullet2 = (GameObject)Instantiate (bullets,playerCamera.transform.position, Quaternion.identity);
         *  Ray rayOrigin = playerCamera.ScreenPointToRay (new Vector3(Screen.width / 2, Screen.height / 2, 0));
         *      Vector3 direction = rayOrigin.direction;
         *      //掛けている20はBulletのスピードなので好きな数値を入力
         * bullet2.GetComponent<Rigidbody> ().velocity = direction * speed; */


        /*Vector3 cameraCenter = new Vector3 (Screen.width / 2, Screen.height / 2, 0);
         *
         * //Raycastで飛ばす光線を作成(Mainカメラの中央部分から飛ばす)
         * Ray ray = playerCamera.ScreenPointToRay (cameraCenter);
         *
         * //Raycastを上記で設定した光線でrange分の距離だけ飛ばす。
         * if (Physics.Raycast (ray, out hit, range)) {
         *      //Raycastで何かヒットしたら実行される。
         *      if (hit.transform.tag == "Enemy") {
         *              //Enemyタグの時のみ実行される。
         *              //Enemyタグを持つオブジェクトにDamage関数を実行する。
         *              //hit.transform.SendMessage("Damage");
         *              Destroy (hit.collider.gameObject);
         *
         *      }*/
        bulletHolder.ConsumeBullet();
        ConsumePower();

        shotSounded.Play();
    }