★(チャレンジセクション)操作方法を改良する






トリガーのセット方法の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject[] shotAnchors;
void Update()
{
if(photonView.IsMine)
{
// ★追加(キーボード操作)
// Aキー押しでトリガーのセット
if(Input.GetKeyDown(KeyCode.A))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
// マウス操作
if (Input.GetMouseButtonDown(0))
{
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);
}
}
}

トリガーの発射方法の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class AsteroidX : MonoBehaviourPunCallbacks
{
private Rigidbody rb;
void Start()
{
TryGetComponent(out rb);
}
void Update()
{
if (photonView.IsMine)
{
// ★追加(キーボード操作)
// Wキー押しでトリガー発射
if(Input.GetKeyDown(KeyCode.W))
{
rb.AddForce(transform.forward * 3000);
}
// マウス操作
if (Input.GetMouseButtonDown(1))
{
rb.AddForce(transform.forward * 3000);
}
}
}
}

【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)
{
// ★追加(キーボード操作)
// Aキー押しでトリガーのセット
if(Input.GetKeyDown(KeyCode.A))
{
foreach (GameObject anchor in shotAnchors)
{
StartCoroutine(Trigger(anchor));
}
}
// マウス操作
if (Input.GetMouseButtonDown(0))
{
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);
}
}
}

トリガーの発射方法の変更
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class AsteroidX : MonoBehaviourPunCallbacks
{
private Rigidbody rb;
void Start()
{
TryGetComponent(out rb);
}
void Update()
{
if (photonView.IsMine)
{
// ★追加(キーボード操作)
// Wキー押しでトリガー発射
if(Input.GetKeyDown(KeyCode.W))
{
rb.AddForce(transform.forward * 3000);
}
// マウス操作
if (Input.GetMouseButtonDown(1))
{
rb.AddForce(transform.forward * 3000);
}
}
}
}

★(チャレンジセクション)操作方法を改良する