Exemple #1
0
        public GameObject SpawnBullet(BulletController.BulletInfo aBulletInfo)
        {
            GameObject player = null;

            GameObject[] planes = GameObject.FindGameObjectsWithTag("Plane");
            for (int i = 0; i < planes.Length; i++)
            {
                if (planes[i].GetComponent <PhotonView>().owner == aBulletInfo.m_shooter)
                {
                    player = planes[i];
                    break;
                }
            }


            if (player != null)
            {
                player.GetComponent <PlaneController>().ResetGunCharge();
                GameObject flare = (GameObject)Instantiate(m_muzzleFlarePrefab, player.GetComponent <PlaneController>().m_bulletSpawnPoint.position, player.GetComponent <PlaneController>().m_bulletSpawnPoint.rotation);
                flare.transform.parent = player.transform;
                flare.GetComponent <AudioSource>().pitch = 1 + Random.Range(-2.0f, 3.0f) * 0.2f;
                if (aBulletInfo.m_shooter == PhotonNetwork.player)
                {
                    flare.GetComponent <AudioSource>().spatialBlend = 0;
                }
                flare.GetComponent <AudioSource>().Play();
            }

            GameObject bullet = (GameObject)Instantiate(((int)aBulletInfo.m_shooter.customProperties["Team"] == 1) ? m_bullet1Prefab : m_bullet2Prefab, aBulletInfo.m_startPosition, Quaternion.LookRotation(aBulletInfo.m_startDirection, -Vector3.forward));

            bullet.GetComponent <Rigidbody>().velocity = aBulletInfo.m_startVelocity;
            bullet.GetComponent <BulletController>().SetBulletInfo(aBulletInfo);

            return(bullet);
        }
        public GameObject SpawnBullet(BulletController.BulletInfo aBulletInfo)
        {
            GameObject player = null;

            GameObject[] planes = GameObject.FindGameObjectsWithTag("PlayerController");
            for (int i = 0; i < planes.Length; i++)
            {
                if (planes[i].GetComponent <PlaneController>().m_playerID == aBulletInfo.m_shooter)
                {
                    player = planes[i];
                    break;
                }
            }


            if (player != null)
            {
                player.GetComponent <PlaneController>().ResetGunCharge();
                GameObject flare = (GameObject)Instantiate(m_muzzleFlarePrefab, aBulletInfo.m_startPosition, player.GetComponent <PlaneController>().m_bulletSpawnPoint.rotation);
                flare.transform.parent = player.transform;
                flare.GetComponent <AudioSource>().pitch = 1 + Random.Range(-2.0f, 3.0f) * 0.2f;
                if (aBulletInfo.m_shooter == BombersNetworkManager.m_localPlayer.m_playerID)
                {
                    flare.GetComponent <AudioSource>().spatialBlend = 0;
                }
                NetworkServer.Spawn(flare);
            }
            int        team   = GetComponent <BombersPlayerController>().m_team;
            GameObject bullet = (GameObject)Instantiate((team == 1) ? m_bullet1Prefab : m_bullet2Prefab, aBulletInfo.m_startPosition, Quaternion.LookRotation(aBulletInfo.m_startDirection, -Vector3.forward));

            bullet.GetComponent <Rigidbody>().velocity = aBulletInfo.m_startVelocity;
            bullet.GetComponent <BulletController>().SetBulletInfo(aBulletInfo);

            return(bullet);
        }
        void CmdSpawnBullet()
        {
            int id = Random.Range(-20000000, 20000000) * 100 + m_playerID;
            //Transform m_bulletSpawnPoint = aSpawnPoint;
            Transform m_bulletSpawnPoint = m_playerPlane.GetComponent<PlaneController>().m_bulletSpawnPoint;
            Vector3 m_bulletVelocity = m_bulletSpawnPoint.forward.normalized;
            m_bulletVelocity *= GetComponent<WeaponController>().m_bulletSpeed;
            m_bulletVelocity += m_playerPlane.GetComponent<Rigidbody>().velocity;
            BulletController.BulletInfo aBulletInfo = new BulletController.BulletInfo(m_bulletSpawnPoint.position, m_bulletSpawnPoint.forward.normalized, m_playerID, m_bulletVelocity, id);
            aBulletInfo.m_isMaster = true;
            GameObject bullet = GetComponent<WeaponController>().SpawnBullet(aBulletInfo);
            m_gMan.m_spawnedBullets.Add(bullet.GetComponent<BulletController>().GetBulletInfo());
            bullet.GetComponent<Collider>().isTrigger = false;
            switch (m_team)
            {
                case 1:
                    bullet.layer = 10;
                    break;
                case 2:
                    bullet.layer = 11;
                    break;
            }

            NetworkServer.Spawn(bullet);
        }