Note: UNet is deprecated, and will be removed from Unity in the future. A new system is under development. For more information and next steps see this blog post. |
ネットワーク化されたゲームオブジェクトとは Unity のネットワークシステムによって制御され同期されるゲームオブジェクトです。同期されネットワーク化されたゲームオブジェクトを利用すると、ゲームのインスタンスを再生するすべてのプレイヤーが共有できる 1 つの体験を作り出すことができます。ゲーム内で、すべてのプレイヤーは、それぞれ独自の観点からですが、同じ出来事とアクションを見るのです。
Unity のマルチプレイヤーゲームは大抵、ネットワーク化されたゲームオブジェクトと通常の (ネットワーク化されていない) ゲームオブジェクトが混在するシーンで成り立っています。ネットワーク化されたゲームオブジェクトは、ゲームを一緒にプレイしているすべてのユーザー間で必要な同期によって、ゲーム中に移動したり変化したりするものです。ネットワーク化されていないゲームオブジェクトとは、移動や変化をしないオブジェクト (例えば、岩やフェンスなどの静的オブジェクトなど)、または、移動や変化をするゲームオブジェクトであっても、プレイヤー間で同期する必要がないオブジェクト (例えば、微かに揺れる木やゲームの背景を横切る雲など) のことを指します。
ネットワーク化されたゲームオブジェクトには、 Network Identity コンポーネントがアタッチされています。 ただし、Network Identity コンポーネントだけでは、ゲームオブジェクトをマルチプレイヤーゲームで機能させ、アクティブにするには不十分です。Network Identity コンポーネントは同期するための始めの一歩であり、これにより Network Manager がゲームオブジェクトの 作成と破棄 の同期を行うことが可能になります。しかし、それ以外に、ゲームオブジェクトの どのプロパティ を同期するかは指定しません。
ネットワーク化された各ゲームオブジェクトの何が同期されるべきかは、作成するゲームの種類、各ゲームオブジェクトの目的によって異なります。 同期すべき事例には以下のようなものがあります。
プレイヤーキャラクターやノンプレイヤーキャラクターなど、移動するゲームオブジェクトの 位置 と 回転
アニメーション化したゲームオブジェクトの アニメーションステート
変数の 値 (例えば、プレイ中のゲームラウンドの残り時間やプレイヤーに残っている体力など)
上に挙げたもの中には、Unity によって自動的に同期されるものもあります。 ネットワーク化されたゲームオブジェクトの同期による生成と破棄は、NetworkManager によって管理され、スポーン と呼ばれています。Network Transform コンポーネントを使用するとゲームオブジェクトの位置と回転を同期させ、 Network Animator コンポーネントを使用するとゲームオブジェクトのアニメーションを同期させることができます。
ネットワーク化されたゲームオブジェクトの他のプロパティを同期するには、スクリプトを使用する必要があります。 詳細については、ステートの同期 を参照してください。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.