実現したいこと
自分の生成したカメラを操作したい
現状
自分の生成したステージの子オジェクトのカメラじゃなく相手の生成したカメラが動いてしまう
キーでは移動できるがボタンで移動できない。キャンバスが二つ生成されるので下記のせいでキャンセルされていると思うがいい対処法がわからない
if (EventSystem.current.IsPointerOverGameObject())
{
// かぶさってるので処理キャンセル(マウスクver)
return;
}
if (Input.touchCount > 0 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
// かぶさってるので処理キャンセル(タップver)
return;
}
)
試したこと
カメラを最初からステージに用意して後から子オブジェクトにしたがpublicからbuttonなどが消えて押しても意味がなくなった
該当コード
ステージ生成
public class GameControllerOnline : MonoBehaviourPunCallbacks { public GameObject wincanvas; public GameObject win; public GameObject lose; // Start is called before the first frame update void Start() { wincanvas.SetActive(false); win.SetActive(false); lose.SetActive(false); Player player = PhotonNetwork.LocalPlayer; if (player.IsMasterClient) { PhotonNetwork.Instantiate("CreateModeOnline", Vector3.zero, Quaternion.identity); } else { PhotonNetwork.Instantiate("CreateModeOnline", new Vector3(1000, 0, 0), Quaternion.identity); } } // Update is called once per frame void Update() { } public void HostWin() { Player player = PhotonNetwork.LocalPlayer; if (player.IsMasterClient) { win.SetActive(true); wincanvas.SetActive(true); } else { lose.SetActive(true); wincanvas.SetActive(true); } } public void GuestWin() { Player player = PhotonNetwork.LocalPlayer; if (player.IsMasterClient) { lose.SetActive(true); wincanvas.SetActive(true); } else { win.SetActive(true); wincanvas.SetActive(true); } } }
カメラ
public class StageObjectOnline : MonoBehaviourPunCallbacks { private Vector3 vec; public Button create; public GameObject target; private Vector2 mouse; private GameObject Stage; private GameObject player; private Vector3 velocity; private float speed = 100; private bool up; private bool down; public Text costtext; int cost; public Image createplayer; float count = 45; public GameObject tap; public GameObject createcanvas; AudioListener main; private GameObject root; // Start is called before the first frame update void Start() { target.SetActive(false); cost = PlayerPrefs.GetInt("Cost"); costtext.text = "Cost : " + cost; main = gameObject.GetComponent<AudioListener>(); createplayer.fillAmount = 0; count = 45; root = transform.root.gameObject; Stage = root.transform.Find("Stage1").gameObject; } // Update is called once per frame void Update() { if (photonView.IsMine) { velocity = Vector3.zero; if (Input.GetKeyDown(KeyCode.W)) { up = true; target.SetActive(false); } else if (Input.GetKeyDown(KeyCode.S)) { down = true; target.SetActive(false); } else if (Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.S)) { up = false; down = false; } if (up == true) { velocity.z += 1; } if (down == true) { velocity.z -= 1; } velocity = velocity.normalized * speed * Time.deltaTime; transform.position += velocity; if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject()) { // かぶさってるので処理キャンセル(マウスクver) return; } if (Input.touchCount > 0 && EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { // かぶさってるので処理キャンセル(タップver) return; } mouse = Input.mousePosition; target.SetActive(true); target.transform.position = mouse; create.interactable = true; } createplayer.fillAmount += 1.0f / count * Time.deltaTime; if (createplayer.fillAmount >= 1) { tap.SetActive(true); } } else { return; } } public void Up() { up = true; } public void Down() { down = true; } public void ButtonUp() { up = false; down = false; } public void Create() { if (photonView.IsMine) { if (cost > 0) { UnityEngine.Ray ray = Camera.main.ScreenPointToRay(mouse); RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Stage")) { create.interactable = true; target.SetActive(true); target.transform.position = mouse; vec = hit.point; Quaternion rotation = Quaternion.Euler(0f, 180f, 0f); GameObject ko = PhotonNetwork.Instantiate("SnowmanBlueOnline", vec, rotation); ko.transform.parent = Stage.transform; int createcost = ko.gameObject.GetComponent<EnemyStatusOnline>().cost; cost -= createcost; costtext.text = "Cost : " + cost; } else { create.interactable = false; } } } else { create.interactable = false; } } else { return; } } public void FindPlayer() { player = GameObject.Find("Player"); } public void Break() { int getcost; getcost = player.GetComponent<PlayerOnline>().Cost(); cost += getcost; costtext.text = "Cost : " + cost; } public void OnCreatePlayer() { if (photonView.IsMine) { if (createplayer.fillAmount >= 1) { Photon.Realtime.Player player = PhotonNetwork.LocalPlayer; if (player.IsMasterClient) { GameObject ko = PhotonNetwork.Instantiate("PlayerParentOnline", new Vector3(1000, 25, 0), Quaternion.identity); ko.transform.parent = Stage.transform; } else { GameObject ko = PhotonNetwork.Instantiate("PlayerParentOnline", new Vector3(0, 25, 0), Quaternion.identity); ko.transform.parent = Stage.transform; } createplayer.fillAmount = 0; tap.SetActive(false); createcanvas.SetActive(false); main.enabled = false; createplayer.fillAmount = 0; cost += PlayerPrefs.GetInt("Cost") / 2; costtext.text = "Cost : " + cost; } } else { return; } } public void PlayerDead() { createcanvas.SetActive(true); main.enabled = true; createplayer.fillAmount = 0; } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。