Exemplo n.º 1
0
    public void OnBulletSpawn(NetworkMessage _networkMessage)
    {
        // Read msg
        BulletSpawnMessage msg = _networkMessage.ReadMessage <BulletSpawnMessage>();

        // Create Bullet
        GameObject clone = Instantiate(this.bullet, msg.position, msg.rotation) as GameObject;

        clone.GetComponent <Bullet>().ownerId = msg.objectId;
        //NetworkServer.Spawn(clone);

        // Set velocity
        clone.GetComponent <Rigidbody>().velocity = clone.transform.forward * msg.speed;

        // Tell client player's to play a particle effect
        ShotBulletMessage newMsg = new ShotBulletMessage();

        newMsg.playerId = msg.objectId;
        NetworkServer.SendToAll(CustomMsgType.ShotBullet, newMsg);
    }
    public void Fire()
    {
        if (!this.canFire)
        {
            return;
        }

        this.canFire = false;

        //GameObject clone = Instantiate(this.bullet, this.bulletSpawn.position, this.bulletSpawn.rotation) as GameObject;

        // Send msg to server to spawn object
        BulletSpawnMessage msg = new BulletSpawnMessage();

        msg.objectId = this.netId;
        msg.position = this.bulletSpawn.position;
        msg.rotation = this.bulletSpawn.rotation;
        msg.speed    = this.bulletSpeed;

        NetworkManager.singleton.client.Send(CustomMsgType.BulletSpawn, msg);

        // Mask network request/spawning speed
        //this.playerMovement.KickBack();
    }