わかりましたので、GUI で行っていない場合は、レイ キャストを使用することをお勧めします。Unity Ray Castingを確認してから使用してください
hit.transform.gameObject.renderer.material.color = red;
次のようなスイッチを使用できます。
if (hit.transform.gameObject.CompareTag("tag")) {
// turn to red;
} else {
// turn to white;
}
何をしているかに応じてScreenPointToRay
またはを使用します。ScreenPointToWorld
タッチの場合、次のようになります。
void Update () {
foreach (Touch touch in Input.touches)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000.0f))
{
if (hit.collider.gameObject.CompareTag("tag"))
{
hit.collider.gameObject.renderer.material.color = red;
}
}
}
// You can also add in a "go back" feature in the update but this will "go back" then when the touch ends or moves off
// Also not so good to search for Objects in the update function but that's at your discretion.
GameObject[] gObjs = GameObject.FindGameObjectsWithTag("tag");
foreach (GameObject go in gObjs) {
go.renderer.material.color = white;
}
}
「マネージャー」へのpingに関する質問に答えるには
私は2つのオプションのうちの1つを行います。また:
// Drop the object containing YourManager into the box in the inspector where it says "manage"
public YourManager manage;
// In the update and in the Ray Cast function (right next to your color change line):
manager.yourCall ();
// and
manager.yourString = "cool";
また
private YourManager manage;
void Awake () {
manager = GameObject.FindObjectWithTag("manager").GetComponent<YourManager> ();
}
// In the update and in the Ray Cast function (right next to your color change line):
// In your manager file have "public bool selected;" at the top so you can access that bool from this file like:
manager.selected = true;
これについては、別の回答で少し詳しく説明しますHERE
マウス クリックの場合は、次のような MonoDevelop 関数をチェックします。
// This file would be on the game object in the scene
// When the mouse is hovering the GameObject
void OnMouseEnter () {
selected = true;
renderer.material.color = red;
}
// When the mouse moved out
void OnMouseExit () {
selected = false;
renderer.material.color = white;
}
// Or you can use the same system as above with the:
Input.GetMouseButtonDown(0))
解像度:
マネージャー ファイルで bool を使用するtrue
が選択されfalse
ていません。インスタンス化するすべてのオブジェクトにタグを付け、マスター ファイルからゲーム オブジェクトへのレイ キャストを使用します。そのタグが付いたゲーム オブジェクトになったら、色を交換し、マスター ファイルから bool を取得します。おそらくマスターファイルから内部的に行う方が良いでしょう。(すべてはあなたが何をしているかに依存します)