ボスの機能の作成④(DarkOption)
DarkOptionの発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public Material[] materials;
private int num = 0;
public GameObject beamPrefab;
public GameObject target;
// ★追加(DarkOption)
public GameObject darkOptionPrefab;
private void Start()
{
StartCoroutine(ChangeColor());
}
private void Update()
{
transform.LookAt(target.transform);
}
private IEnumerator ChangeColor()
{
while (true)
{
yield return new WaitForSeconds(5f);
num = (num + 1) % materials.Length;
this.gameObject.GetComponent<MeshRenderer>().material = materials[num];
// ★追加(DarkOption)
if (num == 2)
{
for (int i = 0; i < 4; i++)
{
GameObject darkOption = Instantiate(darkOptionPrefab, transform.position, Quaternion.identity);
Rigidbody darkOptionRb = darkOption.GetComponent<Rigidbody>();
darkOptionRb.AddForce(new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * 1000);
yield return new WaitForSeconds(0.3f);
darkOptionRb.velocity = Vector3.zero;
Destroy(darkOption, 10.0f);
}
}
if (num == 3)
{
for (int i = 0; i < 7; i++)
{
GameObject beam = Instantiate(beamPrefab, transform.position, transform.rotation);
Rigidbody beamRb = beam.GetComponent<Rigidbody>();
beamRb.AddForce(transform.forward * 1000);
Destroy(beam, 3.0f);
yield return new WaitForSeconds(0.3f);
}
}
}
}
}
【2021版】Danmaku(基礎/全55回)
他のコースを見るDarkOptionの発射
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public Material[] materials;
private int num = 0;
public GameObject beamPrefab;
public GameObject target;
// ★追加(DarkOption)
public GameObject darkOptionPrefab;
private void Start()
{
StartCoroutine(ChangeColor());
}
private void Update()
{
transform.LookAt(target.transform);
}
private IEnumerator ChangeColor()
{
while (true)
{
yield return new WaitForSeconds(5f);
num = (num + 1) % materials.Length;
this.gameObject.GetComponent<MeshRenderer>().material = materials[num];
// ★追加(DarkOption)
if (num == 2)
{
for (int i = 0; i < 4; i++)
{
GameObject darkOption = Instantiate(darkOptionPrefab, transform.position, Quaternion.identity);
Rigidbody darkOptionRb = darkOption.GetComponent<Rigidbody>();
darkOptionRb.AddForce(new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)) * 1000);
yield return new WaitForSeconds(0.3f);
darkOptionRb.velocity = Vector3.zero;
Destroy(darkOption, 10.0f);
}
}
if (num == 3)
{
for (int i = 0; i < 7; i++)
{
GameObject beam = Instantiate(beamPrefab, transform.position, transform.rotation);
Rigidbody beamRb = beam.GetComponent<Rigidbody>();
beamRb.AddForce(transform.forward * 1000);
Destroy(beam, 3.0f);
yield return new WaitForSeconds(0.3f);
}
}
}
}
}
ボスの機能の作成④(DarkOption)