ボスの機能の作成⑥(シールド)
![4845b1c7 6be9 4b3a 8b96 e42d68002254](https://codegenius.org/uploads/slide/image/7794/4845b1c7-6be9-4b3a-8b96-e42d68002254.jpeg)
![D42a5bfc 75c4 40aa b979 d7968dbcfd75](https://codegenius.org/uploads/slide/image/7795/d42a5bfc-75c4-40aa-b979-d7968dbcfd75.jpeg)
![3c0f377f ddce 4151 b8b3 6b9ad19656c0](https://codegenius.org/uploads/slide/image/7796/3c0f377f-ddce-4151-b8b3-6b9ad19656c0.jpeg)
![5c770855 0d9b 42d5 bddf 85df8baab292](https://codegenius.org/uploads/slide/image/7797/5c770855-0d9b-42d5-bddf-85df8baab292.jpeg)
![61b69936 4ef8 49c6 929a e920e2e219f8](https://codegenius.org/uploads/slide/image/7798/61b69936-4ef8-49c6-929a-e920e2e219f8.jpeg)
ボス・シールド
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossShield : MonoBehaviour
{
public AudioClip sound;
private void OnTriggerEnter(Collider other)
{
if(other.TryGetComponent(out Missile missile))
{
Destroy(missile.gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
}
![3faf8a2c 67e7 4ac7 a5a5 9a6eadd05be7](https://codegenius.org/uploads/slide/image/7799/3faf8a2c-67e7-4ac7-a5a5-9a6eadd05be7.jpeg)
![95b95dd7 2066 497a a10f 0031d512dbe5](https://codegenius.org/uploads/slide/image/7800/95b95dd7-2066-497a-a10f-0031d512dbe5.jpeg)
![29896df3 e229 4ced aafd aeb450d2fa33](https://codegenius.org/uploads/slide/image/7801/29896df3-e229-4ced-aafd-aeb450d2fa33.jpeg)
![5364f589 9e46 433e ae5a 4d1963848311](https://codegenius.org/uploads/slide/image/7802/5364f589-9e46-433e-ae5a-4d1963848311.jpeg)
シールドの展開と解除
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;
public GameObject darkOptionPrefab;
// ★追加(シールド)
public GameObject bossShield;
private void Start()
{
StartCoroutine(ChangeColor());
// ★追加(シールド)
bossShield.SetActive(false);
}
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];
// ★追加(シールド)
if(num==1)
{
// シールド展開
bossShield.SetActive(true);
}
if (num == 2)
{
// ★追加(シールド)
// シールド解除
bossShield.SetActive(false);
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);
}
}
}
}
}
![B4760881 377a 4ae1 8242 a44f13ffc2d9](https://codegenius.org/uploads/slide/image/7803/b4760881-377a-4ae1-8242-a44f13ffc2d9.jpeg)
【2021版】Danmaku(基礎/全55回)
他のコースを見る![4845b1c7 6be9 4b3a 8b96 e42d68002254](https://codegenius.org/uploads/slide/image/7794/4845b1c7-6be9-4b3a-8b96-e42d68002254.jpeg)
![D42a5bfc 75c4 40aa b979 d7968dbcfd75](https://codegenius.org/uploads/slide/image/7795/d42a5bfc-75c4-40aa-b979-d7968dbcfd75.jpeg)
![3c0f377f ddce 4151 b8b3 6b9ad19656c0](https://codegenius.org/uploads/slide/image/7796/3c0f377f-ddce-4151-b8b3-6b9ad19656c0.jpeg)
![5c770855 0d9b 42d5 bddf 85df8baab292](https://codegenius.org/uploads/slide/image/7797/5c770855-0d9b-42d5-bddf-85df8baab292.jpeg)
![61b69936 4ef8 49c6 929a e920e2e219f8](https://codegenius.org/uploads/slide/image/7798/61b69936-4ef8-49c6-929a-e920e2e219f8.jpeg)
ボス・シールド
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossShield : MonoBehaviour
{
public AudioClip sound;
private void OnTriggerEnter(Collider other)
{
if(other.TryGetComponent(out Missile missile))
{
Destroy(missile.gameObject);
AudioSource.PlayClipAtPoint(sound, transform.position);
}
}
}
![3faf8a2c 67e7 4ac7 a5a5 9a6eadd05be7](https://codegenius.org/uploads/slide/image/7799/3faf8a2c-67e7-4ac7-a5a5-9a6eadd05be7.jpeg)
![95b95dd7 2066 497a a10f 0031d512dbe5](https://codegenius.org/uploads/slide/image/7800/95b95dd7-2066-497a-a10f-0031d512dbe5.jpeg)
![29896df3 e229 4ced aafd aeb450d2fa33](https://codegenius.org/uploads/slide/image/7801/29896df3-e229-4ced-aafd-aeb450d2fa33.jpeg)
![5364f589 9e46 433e ae5a 4d1963848311](https://codegenius.org/uploads/slide/image/7802/5364f589-9e46-433e-ae5a-4d1963848311.jpeg)
シールドの展開と解除
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;
public GameObject darkOptionPrefab;
// ★追加(シールド)
public GameObject bossShield;
private void Start()
{
StartCoroutine(ChangeColor());
// ★追加(シールド)
bossShield.SetActive(false);
}
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];
// ★追加(シールド)
if(num==1)
{
// シールド展開
bossShield.SetActive(true);
}
if (num == 2)
{
// ★追加(シールド)
// シールド解除
bossShield.SetActive(false);
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);
}
}
}
}
}
![B4760881 377a 4ae1 8242 a44f13ffc2d9](https://codegenius.org/uploads/slide/image/7803/b4760881-377a-4ae1-8242-a44f13ffc2d9.jpeg)
ボスの機能の作成⑥(シールド)