|
@@ -1,10 +1,39 @@
|
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
|
-
|
|
|
|
|
public class Spirits_Invisible : MonoBehaviour
|
|
public class Spirits_Invisible : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
public bool notOut;
|
|
public bool notOut;
|
|
|
|
|
+ public Demonic demonic;
|
|
|
|
|
+ public InvisibleState state;
|
|
|
|
|
+ public Rigidbody rb;
|
|
|
|
|
+ public float moveSpeed;
|
|
|
|
|
+ public float findSoulSpeed;
|
|
|
|
|
+ public float minSpeed;
|
|
|
|
|
+ public float upSpeed;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public float boomSpeed;
|
|
|
|
|
+ public float altitude;
|
|
|
|
|
+ public float randomRageY;
|
|
|
|
|
+ public float randomRageX;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public float offsetY;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public float offsetX;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public Vector3 targetPos;
|
|
|
|
|
+ public float back;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public int hp;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public float posx;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public Soul targetSoul;
|
|
|
|
|
+ public int followNumber;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public int haveSoulNumber;
|
|
|
|
|
+ public SoulFollowEffect followEffect;
|
|
|
|
|
+ public float backSoulX;
|
|
|
// Start is called before the first frame update
|
|
// Start is called before the first frame update
|
|
|
void Start()
|
|
void Start()
|
|
|
{
|
|
{
|
|
@@ -12,11 +41,196 @@ public class Spirits_Invisible : MonoBehaviour
|
|
|
{
|
|
{
|
|
|
gameObject.SetActive(false);
|
|
gameObject.SetActive(false);
|
|
|
}
|
|
}
|
|
|
|
|
+ demonic.isNonAttack = true;
|
|
|
|
|
+ hp = demonic.hp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
// Update is called once per frame
|
|
|
void Update()
|
|
void Update()
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
|
|
+ Onstate();
|
|
|
|
|
+ if (demonic.hp <= 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Die);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ void Onstate()
|
|
|
|
|
+ {
|
|
|
|
|
+ Vector3 pos1;
|
|
|
|
|
+ Vector3 pos2;
|
|
|
|
|
+ switch (state)
|
|
|
|
|
+ {
|
|
|
|
|
+ case InvisibleState.Normal:
|
|
|
|
|
+
|
|
|
|
|
+ if (haveSoulNumber != followNumber && SoulInMap.souls.Count != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.FindSoul);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (hp != demonic.hp)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Hurt);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ posx = PlayersInput.instance[demonic.id].transform.position.x;
|
|
|
|
|
+ targetPos = new Vector3(posx + offsetX, altitude + offsetY, transform.position.z);
|
|
|
|
|
+ Goto(targetPos, moveSpeed);
|
|
|
|
|
+ if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ offsetY = Random.Range(-randomRageY, randomRageY);
|
|
|
|
|
+ offsetX = Random.Range(-randomRageX, randomRageX);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Hurt:
|
|
|
|
|
+ if (haveSoulNumber != followNumber && SoulInMap.souls.Count != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.FindSoul);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Normal);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Goto(targetPos, moveSpeed);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ if (targetSoul.gameObject.activeSelf)
|
|
|
|
|
+ {
|
|
|
|
|
+ pos1 = new Vector3(transform.position.x, transform.position.y, 0);
|
|
|
|
|
+ pos2 = new Vector3(targetSoul.transform.position.x,
|
|
|
|
|
+ targetSoul.transform.position.y, 0);
|
|
|
|
|
+ if (Vector3.Distance(pos1, pos2) <= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ SoulInMap.souls.Remove(targetSoul);
|
|
|
|
|
+ targetSoul.gameObject.SetActive(false);
|
|
|
|
|
+ haveSoulNumber++;
|
|
|
|
|
+ followEffect.ShowSouls(haveSoulNumber);
|
|
|
|
|
+ if (haveSoulNumber == followNumber)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.FindPlayer);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (targetSoul == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Normal);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ targetPos = new Vector3(targetSoul.transform.position.x, targetSoul.transform.position.y,
|
|
|
|
|
+ transform.position.z);
|
|
|
|
|
+
|
|
|
|
|
+ Goto(targetPos, findSoulSpeed);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindPlayer:
|
|
|
|
|
+ pos1 = new Vector3(transform.position.x, transform.position.y, 0);
|
|
|
|
|
+ pos2 = new Vector3(PlayersInput.instance[demonic.id].transform.position.x - backSoulX,
|
|
|
|
|
+ PlayersInput.instance[demonic.id].transform.position.y + 0.5f, 0);
|
|
|
|
|
+ if (Vector3.Distance(pos1, pos2) <= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Boom);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ boomSpeed += Time.deltaTime * upSpeed;
|
|
|
|
|
+ Goto(PlayersInput.instance[demonic.id].transform.position + Vector3.up * 0.5f, boomSpeed);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Boom:
|
|
|
|
|
+ ChangeState(InvisibleState.Normal);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ void ChangeState(InvisibleState newState)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (state)
|
|
|
|
|
+ {
|
|
|
|
|
+ case InvisibleState.Normal:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Hurt:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindPlayer:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Boom:
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (newState)
|
|
|
|
|
+ {
|
|
|
|
|
+ case InvisibleState.Normal:
|
|
|
|
|
+ hp = demonic.hp;
|
|
|
|
|
+ offsetY = Random.Range(-randomRageY, randomRageY);
|
|
|
|
|
+ offsetX = Random.Range(-randomRageX, randomRageX);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Hurt:
|
|
|
|
|
+ posx = transform.position.x;
|
|
|
|
|
+ targetPos = new Vector3(posx + offsetX + back, altitude + offsetY, transform.position.z);
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindPlayer:
|
|
|
|
|
+ boomSpeed = minSpeed;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Boom:
|
|
|
|
|
+ rb.velocity = Vector3.zero;
|
|
|
|
|
+ followEffect.ShowSouls(0);
|
|
|
|
|
+ followEffect.Boom();
|
|
|
|
|
+ haveSoulNumber = 0;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Die:
|
|
|
|
|
+ demonic.isDie = true;
|
|
|
|
|
+ demonic.dieKeepTime = demonic.totalDieKeepTime;
|
|
|
|
|
+ gameObject.SetActive(false);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ state = newState;
|
|
|
|
|
+ }
|
|
|
|
|
+ public void Goto(Vector3 pos, float speed)
|
|
|
|
|
+ {
|
|
|
|
|
+ Vector3 target = (pos - transform.position).normalized;
|
|
|
|
|
+ rb.velocity = target * speed;
|
|
|
|
|
+ }
|
|
|
|
|
+ public void FindSoul()
|
|
|
|
|
+ {
|
|
|
|
|
+ Vector3 pos1;
|
|
|
|
|
+ Vector3 pos2;
|
|
|
|
|
+ List<Soul> souls = SoulInMap.souls;
|
|
|
|
|
+ if (souls.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ targetSoul = null;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ pos1 = new Vector3(souls[0].transform.position.x, souls[0].transform.position.y, 0);
|
|
|
|
|
+ pos2 = new Vector3(transform.position.x, transform.position.y, 0);
|
|
|
|
|
+ float minDistance = Vector3.Distance(pos1, pos2);
|
|
|
|
|
+ int targetSoulId = 0;
|
|
|
|
|
+ for (int i = 1; i < souls.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ pos1 = new Vector3(souls[i].transform.position.x, souls[i].transform.position.y, 0);
|
|
|
|
|
+ pos2 = new Vector3(transform.position.x, transform.position.y, 0);
|
|
|
|
|
+ float distance = Vector3.Distance(pos1, pos2);
|
|
|
|
|
+ if (distance < minDistance)
|
|
|
|
|
+ {
|
|
|
|
|
+ minDistance = distance;
|
|
|
|
|
+ targetSoulId = i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ targetSoul = souls[targetSoulId];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|