ボス専用のアニメーションの作成2























第2形態に移行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public GameObject damageEffectPrefab;
private int hitCount;
private Animator anim;
private void Start()
{
anim = transform.root.GetComponent<Animator>();
Invoke("GoToForm1", 3.0f);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Drone"))
{
hitCount += 1;
Destroy(collision.gameObject);
GameObject effect = Instantiate(damageEffectPrefab, collision.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
if (hitCount == 2)
{
anim.SetTrigger("Back_Idle");
// ★★追加(第2形態に移行)
// 3秒後に第2形態に移行させる
Invoke("GoToForm2", 3.0f);
}
// ★★追加(初期形態に移行)
// ドローン攻撃が通算5回ヒットしたら(条件)
else if (hitCount == 5)
{
// 初期状態に戻るパラメータを名前で呼び出す
anim.SetTrigger("Back_Idle");
}
}
}
void GoToForm1()
{
anim.SetTrigger("Form_1");
}
// ★★追加(第2形態に移行)
void GoToForm2()
{
// 第2形態に移行するパラメータを名前で呼び出す
anim.SetTrigger("Form_2");
}
}

【2019版】X_Mission(基礎/全51回)
他のコースを見る






















第2形態に移行
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossCore : MonoBehaviour
{
public GameObject damageEffectPrefab;
private int hitCount;
private Animator anim;
private void Start()
{
anim = transform.root.GetComponent<Animator>();
Invoke("GoToForm1", 3.0f);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Drone"))
{
hitCount += 1;
Destroy(collision.gameObject);
GameObject effect = Instantiate(damageEffectPrefab, collision.transform.position, Quaternion.identity);
Destroy(effect, 0.5f);
if (hitCount == 2)
{
anim.SetTrigger("Back_Idle");
// ★★追加(第2形態に移行)
// 3秒後に第2形態に移行させる
Invoke("GoToForm2", 3.0f);
}
// ★★追加(初期形態に移行)
// ドローン攻撃が通算5回ヒットしたら(条件)
else if (hitCount == 5)
{
// 初期状態に戻るパラメータを名前で呼び出す
anim.SetTrigger("Back_Idle");
}
}
}
void GoToForm1()
{
anim.SetTrigger("Form_1");
}
// ★★追加(第2形態に移行)
void GoToForm2()
{
// 第2形態に移行するパラメータを名前で呼び出す
anim.SetTrigger("Form_2");
}
}

ボス専用のアニメーションの作成2