(攻撃の作成)複数の発射ポイントを設定する




複数の発射ポイントの設定
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
// ★改良
public GameObject[] shotAnchors;
void Update()
{
if(photonView.IsMine)
{
if (Input.GetMouseButtonDown(0))
{
// ★改良
// 6個のshotAnchorの場所にトリガーを生成する。
foreach(GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
}
}
private IEnumerator Trigger(GameObject point) // ★改良
{
// ★改良
GameObject trigger = PhotonNetwork.Instantiate("AsteroidX", point.transform.position, Camera.main.transform.rotation);
yield return new WaitForSeconds(5f);
if(trigger)
{
PhotonNetwork.Destroy(trigger.gameObject);
}
}
}


【2020版】BattleOnline(基礎/全34回)
他のコースを見る



複数の発射ポイントの設定
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
// ★改良
public GameObject[] shotAnchors;
void Update()
{
if(photonView.IsMine)
{
if (Input.GetMouseButtonDown(0))
{
// ★改良
// 6個のshotAnchorの場所にトリガーを生成する。
foreach(GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
}
}
private IEnumerator Trigger(GameObject point) // ★改良
{
// ★改良
GameObject trigger = PhotonNetwork.Instantiate("AsteroidX", point.transform.position, Camera.main.transform.rotation);
yield return new WaitForSeconds(5f);
if(trigger)
{
PhotonNetwork.Destroy(trigger.gameObject);
}
}
}


(攻撃の作成)複数の発射ポイントを設定する