|
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using TMPro;
|
|
|
using System;
|
|
|
+using Random = UnityEngine.Random;
|
|
|
|
|
|
public class ESpirits_Cook : MonoBehaviour
|
|
|
{
|
|
|
@@ -28,14 +29,14 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
|
|
|
private bool once = false; //死一次
|
|
|
private bool die = false; //厨子命尽
|
|
|
- private bool toCatch = false; //没串了去抓人
|
|
|
+ //private bool toCatch = false; //没串了去抓人
|
|
|
private bool isRunning = false; //开跑
|
|
|
|
|
|
private float activeTime; //厨子已出现的时长
|
|
|
public float activeAniTime; //厨子出现动画的时长
|
|
|
private bool isAct = false; //厨子已经完整出现
|
|
|
|
|
|
- private GameObject[] customers; //厨子的所有顾客
|
|
|
+ private List<GameObject> customers; //厨子的所有顾客
|
|
|
private int count; //顾客数量
|
|
|
|
|
|
public float larger; //顾客变大的程度
|
|
|
@@ -51,6 +52,8 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
private float pastTime;
|
|
|
public float cookTime;
|
|
|
|
|
|
+ private float destX;
|
|
|
+
|
|
|
public enum cookState
|
|
|
{
|
|
|
sell = 0,
|
|
|
@@ -59,6 +62,7 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
run = 3,
|
|
|
cook = 4,
|
|
|
back = 5,
|
|
|
+ first = 6, //刚出生
|
|
|
}
|
|
|
|
|
|
private cookState state;
|
|
|
@@ -73,32 +77,39 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
col.enabled = false;
|
|
|
dia = text.transform.parent.gameObject;
|
|
|
dia.SetActive(false);
|
|
|
- customers = new GameObject[chuan];
|
|
|
- state = 0;
|
|
|
+ customers = new List<GameObject>();
|
|
|
+ destX = DestinationX();
|
|
|
+ text.text = chuan.ToString();
|
|
|
//curLock = Instantiate(lockEffect, cook.transform.position, new Quaternion(0, 0, 0, 0), cook.transform);
|
|
|
}
|
|
|
|
|
|
+ private float DestinationX()
|
|
|
+ {
|
|
|
+ float x = Random.Range(minX, maxX);
|
|
|
+ return x;
|
|
|
+ }
|
|
|
+
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
{
|
|
|
//路过发串
|
|
|
- if (state == cookState.sell && !die && other.gameObject.layer == 7 || other.gameObject.layer == 8 || other.gameObject.layer == 6)
|
|
|
+ if (state == cookState.sell && !die && (other.gameObject.layer == 7 || other.gameObject.layer == 8 || other.gameObject.layer == 6))
|
|
|
{
|
|
|
if (chuan > 0)
|
|
|
{
|
|
|
GameObject ga = other.transform.parent.parent.parent.gameObject;
|
|
|
Character ca = ga.GetComponent<Character>();
|
|
|
- if (Array.IndexOf(customers, ga) == -1)
|
|
|
+ if (!customers.Exists(T => T == ga))
|
|
|
{
|
|
|
chuan -= 1;
|
|
|
text.text = chuan.ToString();
|
|
|
ani.Play("attack_march", 0, 0);
|
|
|
ca.HpUp(value, larger);
|
|
|
- customers[count] = ga;
|
|
|
+ customers.Add(ga);
|
|
|
count += 1;
|
|
|
//Instantiate(effect, ga.transform.position, new Quaternion(0, 0, 0, 0), ga.transform);
|
|
|
if (chuan == 0)
|
|
|
{
|
|
|
- toCatch = true;
|
|
|
+ //toCatch = true;
|
|
|
ChangeState(cookState.walk);
|
|
|
}
|
|
|
}
|
|
|
@@ -107,26 +118,30 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
//抓人
|
|
|
else if (state == cookState.run || state == cookState.find || state == cookState.walk && !once)
|
|
|
{
|
|
|
- if (other.gameObject.layer == 7 || other.gameObject.layer == 6)
|
|
|
+ if (other.gameObject.layer == 6 || other.gameObject.layer == 7)
|
|
|
{
|
|
|
food = other.transform.parent.parent.parent.gameObject;
|
|
|
if (food.layer == 7 && !food.GetComponent<Demonic>().isDie)
|
|
|
{
|
|
|
- print(11111111);
|
|
|
food.GetComponent<Demonic>().ChangeState(CharacterState.Die);
|
|
|
//cookKillEffect.SetActive(true);
|
|
|
ChangeState(cookState.cook);
|
|
|
- print(22222222);
|
|
|
}
|
|
|
- else if (food.layer == 6 && !food.GetComponent<Demonic>().isDie)
|
|
|
+ else if (food.layer == 6 && !food.GetComponent<PlayerController>().isDie)
|
|
|
{
|
|
|
food.GetComponent<PlayerController>().ChangeState(CharacterState.Die);
|
|
|
//cookKillEffect.SetActive(true);
|
|
|
ChangeState(cookState.cook);
|
|
|
- print(state);
|
|
|
}
|
|
|
+ chuan = food.GetComponent<Character>().cookNum;
|
|
|
+ text.text = chuan.ToString();
|
|
|
}
|
|
|
}
|
|
|
+ //回家卖串
|
|
|
+ else if (state == cookState.back && !die && other.gameObject.layer == 8)
|
|
|
+ {
|
|
|
+ ChangeState(cookState.sell);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void ChangeState(cookState cs)
|
|
|
@@ -135,7 +150,9 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
{
|
|
|
//卖串中
|
|
|
case cookState.sell:
|
|
|
+ dia.SetActive(true);
|
|
|
ene.isBack = false;
|
|
|
+ ene.canMove = false;
|
|
|
//不能被攻击
|
|
|
foreach (GameObject g in colliders)
|
|
|
{
|
|
|
@@ -157,7 +174,6 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
case cookState.find:
|
|
|
ene.ChangeState(CharacterState.FindPlayer);
|
|
|
break;
|
|
|
-
|
|
|
//冲刺中
|
|
|
case cookState.run:
|
|
|
foreach (GameObject g in colliders)
|
|
|
@@ -167,14 +183,22 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
break;
|
|
|
//鲨人中
|
|
|
case cookState.cook:
|
|
|
- ani.Play("attack_march", 0, 0);
|
|
|
ene.canMove = false;
|
|
|
+ ani.Play("attack_march", 0, 0);
|
|
|
break;
|
|
|
//返回中
|
|
|
case cookState.back:
|
|
|
ene.canMove = true;
|
|
|
ene.isBack = true;
|
|
|
break;
|
|
|
+ case cookState.first:
|
|
|
+ dia.SetActive(false);
|
|
|
+ ene.canMove = true;
|
|
|
+ foreach (GameObject g in colliders)
|
|
|
+ {
|
|
|
+ g.SetActive(true);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -215,6 +239,10 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
}
|
|
|
break;
|
|
|
case cookState.back:
|
|
|
+ if (cook.transform.position.x <= destX)
|
|
|
+ {
|
|
|
+ ChangeState(cookState.sell);
|
|
|
+ }
|
|
|
break;
|
|
|
case cookState.cook:
|
|
|
pastTime += Time.deltaTime;
|
|
|
@@ -229,6 +257,12 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
break;
|
|
|
case cookState.sell:
|
|
|
break;
|
|
|
+ case cookState.first:
|
|
|
+ if (cook.transform.position.x >= destX)
|
|
|
+ {
|
|
|
+ ChangeState(cookState.sell);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -244,6 +278,7 @@ public class ESpirits_Cook : MonoBehaviour
|
|
|
dia.SetActive(true);
|
|
|
isAct = true;
|
|
|
col.enabled = true;
|
|
|
+ ChangeState(cookState.first);
|
|
|
}
|
|
|
}
|
|
|
else
|