示例#1
0
    void Update()
    {
        if (GetComponent <ObservableView>())
        {
            ObservableView  observableView = GetComponent <ObservableView>();
            NetworkedPlayer owner          = EdgeManager.GetPlayer(observableView.ownerId);
            Material        playerMat      = owner.GetComponent <MeshRenderer>().material;
            GetComponent <MeshRenderer>().material = playerMat;
            if (owner.isLocalPlayer)
            {
                float h = Input.GetAxis("Horizontal") * 100 * Time.deltaTime;
                float v = Input.GetAxis("Vertical") * Time.deltaTime;
                transform.Translate(0, 0, v);
                transform.Rotate(0, h, 0);

                if (Input.GetKeyDown(KeyCode.Space))
                {
                    Observable      observable = owner.observer.observables[observableView.observableIndex];
                    NetworkedPlayer otherPlayer;

                    //Switch ownership to the other player in the room
                    if (owner.playerIndex == 0)
                    {
                        otherPlayer = EdgeManager.GetPlayer(1);
                    }
                    else
                    {
                        otherPlayer = EdgeManager.GetPlayer(0);
                    }
                    observable.ChangeOwnership(otherPlayer.playerId);
                }
            }
        }
    }