ボスの機能の作成④(DarkOption)
![D8c5514c 923e 4d10 bf46 e450249ece27](https://codegenius.org/uploads/slide/image/7772/d8c5514c-923e-4d10-bf46-e450249ece27.jpeg)
![F5d32aef 430e 4d23 97cd 6617ca8b3401](https://codegenius.org/uploads/slide/image/7773/f5d32aef-430e-4d23-97cd-6617ca8b3401.jpeg)
![A3c0d27a a2a1 4649 8beb ffa42111a512](https://codegenius.org/uploads/slide/image/7774/a3c0d27a-a2a1-4649-8beb-ffa42111a512.jpeg)
![1f3d46bc e0ed 4daa 95e9 8efe39dad70f](https://codegenius.org/uploads/slide/image/7775/1f3d46bc-e0ed-4daa-95e9-8efe39dad70f.jpeg)
![D721e3ae 15c7 43b9 8df2 3594ce9bb7a2](https://codegenius.org/uploads/slide/image/7776/d721e3ae-15c7-43b9-8df2-3594ce9bb7a2.jpeg)
![9b075de3 5754 4b25 aeec dee8cc8b0998](https://codegenius.org/uploads/slide/image/7777/9b075de3-5754-4b25-aeec-dee8cc8b0998.jpeg)
![8e368e3f a688 4dd7 b811 b5a2758958a9](https://codegenius.org/uploads/slide/image/7778/8e368e3f-a688-4dd7-b811-b5a2758958a9.jpeg)
![E33c410f 2b68 43f0 a4d1 337aee1cd89f](https://codegenius.org/uploads/slide/image/7779/e33c410f-2b68-43f0-a4d1-337aee1cd89f.jpeg)
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);
}
}
}
}
}
![B6678141 3146 4dd1 bc25 1635a4413496](https://codegenius.org/uploads/slide/image/7780/b6678141-3146-4dd1-bc25-1635a4413496.jpeg)
【2021版】Danmaku(基礎/全55回)
他のコースを見る![D8c5514c 923e 4d10 bf46 e450249ece27](https://codegenius.org/uploads/slide/image/7772/d8c5514c-923e-4d10-bf46-e450249ece27.jpeg)
![F5d32aef 430e 4d23 97cd 6617ca8b3401](https://codegenius.org/uploads/slide/image/7773/f5d32aef-430e-4d23-97cd-6617ca8b3401.jpeg)
![A3c0d27a a2a1 4649 8beb ffa42111a512](https://codegenius.org/uploads/slide/image/7774/a3c0d27a-a2a1-4649-8beb-ffa42111a512.jpeg)
![1f3d46bc e0ed 4daa 95e9 8efe39dad70f](https://codegenius.org/uploads/slide/image/7775/1f3d46bc-e0ed-4daa-95e9-8efe39dad70f.jpeg)
![D721e3ae 15c7 43b9 8df2 3594ce9bb7a2](https://codegenius.org/uploads/slide/image/7776/d721e3ae-15c7-43b9-8df2-3594ce9bb7a2.jpeg)
![9b075de3 5754 4b25 aeec dee8cc8b0998](https://codegenius.org/uploads/slide/image/7777/9b075de3-5754-4b25-aeec-dee8cc8b0998.jpeg)
![8e368e3f a688 4dd7 b811 b5a2758958a9](https://codegenius.org/uploads/slide/image/7778/8e368e3f-a688-4dd7-b811-b5a2758958a9.jpeg)
![E33c410f 2b68 43f0 a4d1 337aee1cd89f](https://codegenius.org/uploads/slide/image/7779/e33c410f-2b68-43f0-a4d1-337aee1cd89f.jpeg)
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);
}
}
}
}
}
![B6678141 3146 4dd1 bc25 1635a4413496](https://codegenius.org/uploads/slide/image/7780/b6678141-3146-4dd1-bc25-1635a4413496.jpeg)
ボスの機能の作成④(DarkOption)