public void CreateBullets()
        {
            Vector3[] vectorBase = { _rigidbody.rotation *Vector3.right, _rigidbody.rotation *Vector3.up, _rigidbody.rotation *Vector3.forward };
            Vector3[] offsets    = { -1.5f * vectorBase[0] + -0.5f * vectorBase[2], 1.5f * vectorBase[0] + -0.5f * vectorBase[2] };

            for (int i = 0; i < 2; ++i)
            {
                GameObject             bullet       = Instantiate(bulletPrefab, _rigidbody.position + offsets[i], Quaternion.identity) as GameObject;
                NetworkSpaceshipBullet bulletScript = bullet.GetComponent <NetworkSpaceshipBullet>();

                bulletScript.originalDirection = vectorBase[2];
                bulletScript.owner             = this;

                //NetworkServer.SpawnWithClientAuthority(bullet, connectionToClient);
            }
        }
Esempio n. 2
0
        void OnCollisionEnter(Collision collision)
        {
            //we collide so we dirty the NetworkTrasnform to sync it on clients.
            _netTransform.SetDirtyBit(1);

            if (collision.gameObject.tag == "Fire")
            {
                NetworkSpaceshipBullet bullet = collision.gameObject.GetComponent <NetworkSpaceshipBullet>();

                bullet.owner.score += level;

                Explode();
            }
            else if (collision.gameObject.tag == "Player")
            {//we collided with the player, destroy it.
                NetworkSpaceship ship = collision.gameObject.GetComponent <NetworkSpaceship>();
                ship.Kill();
                Explode();
            }
        }