|
@@ -6,6 +6,7 @@ public enum InvisibleState
|
|
|
None = -1,
|
|
None = -1,
|
|
|
Normal = 0, //Õý³£×´Ì¬
|
|
Normal = 0, //Õý³£×´Ì¬
|
|
|
Hurt = 1, //±»´ò״̬
|
|
Hurt = 1, //±»´ò״̬
|
|
|
|
|
+ FindSoul = 2, //ÕÒ»ê״̬
|
|
|
}
|
|
}
|
|
|
public class ESpirits_Invisible : MonoBehaviour
|
|
public class ESpirits_Invisible : MonoBehaviour
|
|
|
{
|
|
{
|
|
@@ -33,6 +34,8 @@ public class ESpirits_Invisible : MonoBehaviour
|
|
|
public Enemy enemy;
|
|
public Enemy enemy;
|
|
|
[HideInInspector]
|
|
[HideInInspector]
|
|
|
public float posx;
|
|
public float posx;
|
|
|
|
|
+ [HideInInspector]
|
|
|
|
|
+ public Soul targetSoul;
|
|
|
private void Awake()
|
|
private void Awake()
|
|
|
{
|
|
{
|
|
|
hp = enemy.hp;
|
|
hp = enemy.hp;
|
|
@@ -40,6 +43,7 @@ public class ESpirits_Invisible : MonoBehaviour
|
|
|
private void Update()
|
|
private void Update()
|
|
|
{
|
|
{
|
|
|
OnState();
|
|
OnState();
|
|
|
|
|
+ //print(SoulInMap.souls.Count);
|
|
|
}
|
|
}
|
|
|
void OnState()
|
|
void OnState()
|
|
|
{
|
|
{
|
|
@@ -47,15 +51,17 @@ public class ESpirits_Invisible : MonoBehaviour
|
|
|
switch (state)
|
|
switch (state)
|
|
|
{
|
|
{
|
|
|
case InvisibleState.Normal:
|
|
case InvisibleState.Normal:
|
|
|
|
|
+ if (SoulInMap.souls.Count != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.FindSoul);
|
|
|
|
|
+ }
|
|
|
if (hp != enemy.hp)
|
|
if (hp != enemy.hp)
|
|
|
{
|
|
{
|
|
|
- posx = transform.position.x;
|
|
|
|
|
- state = InvisibleState.Hurt;
|
|
|
|
|
|
|
+ ChangeState(InvisibleState.Hurt);
|
|
|
}
|
|
}
|
|
|
- posx = Mathf.Min(PlayersInput.instance[0].transform.position.x,
|
|
|
|
|
- PlayersInput.instance[1].transform.position.x);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ //posx = Mathf.Min(PlayersInput.instance[0].transform.position.x,
|
|
|
|
|
+ // PlayersInput.instance[1].transform.position.x);
|
|
|
|
|
+ posx = PlayersInput.instance[nowPlayer].transform.position.x;
|
|
|
targetPos = new Vector3(posx + offsetX,altitude + offsetY, 0);
|
|
targetPos = new Vector3(posx + offsetX,altitude + offsetY, 0);
|
|
|
Goto(targetPos,moveSpeed);
|
|
Goto(targetPos,moveSpeed);
|
|
|
if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
@@ -72,26 +78,101 @@ public class ESpirits_Invisible : MonoBehaviour
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case InvisibleState.Hurt:
|
|
case InvisibleState.Hurt:
|
|
|
- targetPos = new Vector3(posx + offsetX - back,
|
|
|
|
|
- altitude + offsetY, 0);
|
|
|
|
|
- Goto(targetPos, moveSpeed);
|
|
|
|
|
|
|
+ if (SoulInMap.souls.Count != 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.FindSoul);
|
|
|
|
|
+ }
|
|
|
if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
if (Vector3.Distance(targetPos, transform.position) < 1)
|
|
|
{
|
|
{
|
|
|
-
|
|
|
|
|
- offsetY = Random.Range(-randomRageY, randomRageY);
|
|
|
|
|
- offsetX = Random.Range(-randomRageX, randomRageX);
|
|
|
|
|
- hp = enemy.hp;
|
|
|
|
|
- state = InvisibleState.Normal;
|
|
|
|
|
|
|
+ ChangeState(InvisibleState.Normal);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ Goto(targetPos, moveSpeed);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ if (targetSoul.gameObject.activeSelf)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(Vector3.Distance(transform.position, targetSoul.transform.position) <= 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ SoulInMap.souls.Remove(targetSoul);
|
|
|
|
|
+ //targetSoul.gameObject.SetActive(false);
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ }
|
|
|
|
|
+ if(targetSoul == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ ChangeState(InvisibleState.Normal);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ targetPos = targetSoul.transform.position;
|
|
|
|
|
+ Goto(targetPos, upMoveSpeed);
|
|
|
|
|
+
|
|
|
break;
|
|
break;
|
|
|
default:
|
|
default:
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ public void ChangeState(InvisibleState newState)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (state)
|
|
|
|
|
+ {
|
|
|
|
|
+ case InvisibleState.Normal:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Hurt:
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (newState)
|
|
|
|
|
+ {
|
|
|
|
|
+ case InvisibleState.Normal:
|
|
|
|
|
+ hp = enemy.hp;
|
|
|
|
|
+ offsetY = Random.Range(-randomRageY, randomRageY);
|
|
|
|
|
+ offsetX = Random.Range(-randomRageX, randomRageX);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.Hurt:
|
|
|
|
|
+ targetPos = new Vector3(posx + offsetX - back, altitude + offsetY, 0);
|
|
|
|
|
+ posx = transform.position.x;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case InvisibleState.FindSoul:
|
|
|
|
|
+ FindSoul();
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ state = newState;
|
|
|
|
|
+ }
|
|
|
public void Goto(Vector3 pos,float speed)
|
|
public void Goto(Vector3 pos,float speed)
|
|
|
{
|
|
{
|
|
|
Vector3 target = (pos - transform.position).normalized;
|
|
Vector3 target = (pos - transform.position).normalized;
|
|
|
rb.velocity = target * speed;
|
|
rb.velocity = target * speed;
|
|
|
}
|
|
}
|
|
|
|
|
+ public void FindSoul()
|
|
|
|
|
+ {
|
|
|
|
|
+ List<Soul> souls = SoulInMap.souls;
|
|
|
|
|
+ if(souls.Count == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ targetSoul = null;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ float minDistance = Vector3.Distance(souls[0].transform.position, transform.position);
|
|
|
|
|
+ int targetSoulId = 0;
|
|
|
|
|
+ for(int i = 1; i < souls.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ float distance = Vector3.Distance(souls[i].transform.position, transform.position);
|
|
|
|
|
+ if (distance < minDistance)
|
|
|
|
|
+ {
|
|
|
|
|
+ minDistance = distance;
|
|
|
|
|
+ targetSoulId = i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ targetSoul = souls[targetSoulId];
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|