protected virtual void Awake() { // 共通の初期設定 animation_type = AnimaionType.walk; agent = GetComponent <NavMeshAgent>(); // アニメーションのためにモデルを子供に置く GameObject obj = transform.GetChild(0).gameObject; anim = obj.GetComponent <Animator>(); default_material = GetComponent <Renderer>().material; // 子供のレンダラーをすべて取得 var child_objects = GetComponentsInChildren <Transform>().Select(t => t.gameObject).ToArray(); foreach (GameObject child in child_objects) { // レンダラーがなければ削除する // ブタのエフェクトも例外 if (child.GetComponent <Renderer>() == null || child.name == "pig_poop") { continue; } child_renderer_list.Add(child.GetComponent <Renderer>()); } range = 2.0f; death_time = 0.0f; attack_time = 20.0f; damage_timer = 0.0f; is_damage = false; SetSpeed(status.speed); }
/// <summary> /// ダメージを受けるメソッド(ダメージ量, ギミックかどうか) /// </summary> /// <param name="d"></param> /// <param name="gimick"></param> public void SetDamage(int d, bool gimick = false) { if (this == null) { return; } status.hp -= d; // ギミックだと音と、ダメージの表現がなし if (gimick && character_type == CharacterType.human) { return; } Sound.Instance.PlaySound(Sound.SoundName.damage); // 他の部位も色を変更 for (int i = 0; i < child_renderer_list.Count; i++) { child_renderer_list[i].material = damage_material; } is_damage = true; // 人間ならタイプをダメージに変更 if (character_type == CharacterType.human && animation_type != AnimaionType.attack) { animation_type = AnimaionType.damage; } }
/// <summary> /// アニメーションの変更を制御する /// </summary> private void AnimationControl() { if (status.hp <= 0.0f) { Deth(); return; } // ターゲットが見つからないならアイドル状態に if (target_object == null) { animation_type = AnimaionType.idol; anim.SetBool("isAttack", false); anim.SetBool("isIdol", true); return; } float distance = Vector3.Distance(transform.position, target_object.transform.position); if (animation_type == AnimaionType.damage) { return; } // 近づいたら攻撃 if (distance <= range) { animation_type = AnimaionType.attack; // とりあえず仮 anim.SetBool("isAttack", true); } // 離れれば再び追いかける else if (distance > 5.0f || animation_type != AnimaionType.attack) { animation_type = AnimaionType.walk; // とりあえず仮 anim.SetBool("isAttack", false); } }
protected virtual void Deth() { animation_type = AnimaionType.death; SetSpeed(0); Destroy(gameObject); }