(攻撃の作成)選択したトリガーを画面に表示する
選択したトリガーを画面に表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
// ★追加
using UnityEngine.UI;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject[] shotAnchors;
public string[] triggers;
private int num = 0;
public GameObject markPrefab;
// ★追加
public Text triggerLabel;
// ★追加
private void Start()
{
triggerLabel = GameObject.Find("TriggerLabel").GetComponent<Text>();
// triggerx[0]はAsteroidXに対応
// triggerx[1]はHoundXに対応
triggerLabel.text = triggers[num];
}
void Update()
{
if(photonView.IsMine)
{
if(Input.GetKeyDown(KeyCode.D))
{
num = (num + 1) % triggers.Length;
// ★追加
// Dキーを押すごとにトリガーの表示が変化する。
triggerLabel.text = triggers[num];
}
if(Input.GetKeyDown(KeyCode.A))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
if(num == 1)
{
StartCoroutine(SetMark());
}
}
if (Input.GetMouseButtonDown(0))
{
foreach(GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
}
}
private IEnumerator Trigger(GameObject point)
{
GameObject trigger = PhotonNetwork.Instantiate(triggers[num], point.transform.position, Camera.main.transform.rotation);
yield return new WaitForSeconds(5f);
if(trigger)
{
PhotonNetwork.Destroy(trigger.gameObject);
}
}
private IEnumerator SetMark()
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
{
GameObject mark = Instantiate(markPrefab, hit.point, Quaternion.identity);
yield return new WaitForSeconds(5f);
Destroy(mark);
}
}
}
【2020版】BattleOnline(基礎/全34回)
他のコースを見る選択したトリガーを画面に表示する
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
// ★追加
using UnityEngine.UI;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject[] shotAnchors;
public string[] triggers;
private int num = 0;
public GameObject markPrefab;
// ★追加
public Text triggerLabel;
// ★追加
private void Start()
{
triggerLabel = GameObject.Find("TriggerLabel").GetComponent<Text>();
// triggerx[0]はAsteroidXに対応
// triggerx[1]はHoundXに対応
triggerLabel.text = triggers[num];
}
void Update()
{
if(photonView.IsMine)
{
if(Input.GetKeyDown(KeyCode.D))
{
num = (num + 1) % triggers.Length;
// ★追加
// Dキーを押すごとにトリガーの表示が変化する。
triggerLabel.text = triggers[num];
}
if(Input.GetKeyDown(KeyCode.A))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
if(num == 1)
{
StartCoroutine(SetMark());
}
}
if (Input.GetMouseButtonDown(0))
{
foreach(GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
}
}
private IEnumerator Trigger(GameObject point)
{
GameObject trigger = PhotonNetwork.Instantiate(triggers[num], point.transform.position, Camera.main.transform.rotation);
yield return new WaitForSeconds(5f);
if(trigger)
{
PhotonNetwork.Destroy(trigger.gameObject);
}
}
private IEnumerator SetMark()
{
RaycastHit hit;
if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit))
{
GameObject mark = Instantiate(markPrefab, hit.point, Quaternion.identity);
yield return new WaitForSeconds(5f);
Destroy(mark);
}
}
}
(攻撃の作成)選択したトリガーを画面に表示する