(攻撃の作成)AsteroidXの作成








トリガーの生成&削除
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class ShotTrigger : MonoBehaviourPunCallbacks
{
public GameObject shotAnchor;
void Update()
{
if(photonView.IsMine)
{
// マウス左ボタンでトリガーセット
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(Trigger());
}
}
}
// コルーチン
// トリガーの生成&自動削除
private IEnumerator Trigger()
{
// ネットワーク上に生成
GameObject trigger = PhotonNetwork.Instantiate("AsteroidX", shotAnchor.transform.position, Camera.main.transform.rotation);
// 5秒間待機
yield return new WaitForSeconds(5f);
// 待機後、トリガーがまだ存在するならば
if(trigger)
{
// 生成したトリガーをネットワーク上から削除する。
PhotonNetwork.Destroy(trigger.gameObject);
}
}
}


AsteroidX
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)
{
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 shotAnchor;
void Update()
{
if(photonView.IsMine)
{
// マウス左ボタンでトリガーセット
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(Trigger());
}
}
}
// コルーチン
// トリガーの生成&自動削除
private IEnumerator Trigger()
{
// ネットワーク上に生成
GameObject trigger = PhotonNetwork.Instantiate("AsteroidX", shotAnchor.transform.position, Camera.main.transform.rotation);
// 5秒間待機
yield return new WaitForSeconds(5f);
// 待機後、トリガーがまだ存在するならば
if(trigger)
{
// 生成したトリガーをネットワーク上から削除する。
PhotonNetwork.Destroy(trigger.gameObject);
}
}
}


AsteroidX
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)
{
if (Input.GetMouseButtonDown(1))
{
rb.AddForce(transform.forward * 3000);
}
}
}
}


(攻撃の作成)AsteroidXの作成