(攻撃の作成)選択したトリガーを画面に表示する
選択したトリガーの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
// ★追加
using TMPro;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject[] shotAnchors;
public string[] triggers;
private int num = 0;
public GameObject markPrefab;
// ★追加
private TextMeshProUGUI triggerNameLabel;
public AudioClip changeSound;
private void Start()
{
triggerNameLabel = GameObject.Find("TriggerNameLabel").GetComponent<TextMeshProUGUI>();
triggerNameLabel.text = triggers[num];
}
void Update()
{
if (photonView.IsMine)
{
if (Input.GetKeyDown(KeyCode.W))
{
num = (num + 1) % triggers.Length;
// ★追加
AudioSource.PlayClipAtPoint(changeSound, Camera.main.transform.position);
triggerNameLabel.text = triggers[num];
}
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.D))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
if (triggers[num] == "HoundX")
{
StartCoroutine(SetMark());
}
}
}
}
private IEnumerator Trigger(GameObject createPoint)
{
GameObject trigger = PhotonNetwork.Instantiate(triggers[num], createPoint.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);
}
}
}
【2021版】BattleOnline(全37回)
他のコースを見る選択したトリガーの表示
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
// ★追加
using TMPro;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject[] shotAnchors;
public string[] triggers;
private int num = 0;
public GameObject markPrefab;
// ★追加
private TextMeshProUGUI triggerNameLabel;
public AudioClip changeSound;
private void Start()
{
triggerNameLabel = GameObject.Find("TriggerNameLabel").GetComponent<TextMeshProUGUI>();
triggerNameLabel.text = triggers[num];
}
void Update()
{
if (photonView.IsMine)
{
if (Input.GetKeyDown(KeyCode.W))
{
num = (num + 1) % triggers.Length;
// ★追加
AudioSource.PlayClipAtPoint(changeSound, Camera.main.transform.position);
triggerNameLabel.text = triggers[num];
}
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.D))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
if (triggers[num] == "HoundX")
{
StartCoroutine(SetMark());
}
}
}
}
private IEnumerator Trigger(GameObject createPoint)
{
GameObject trigger = PhotonNetwork.Instantiate(triggers[num], createPoint.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);
}
}
}
(攻撃の作成)選択したトリガーを画面に表示する