Refactoring of status system to prevent bug w/ events
This commit is contained in:
parent
fd8306645b
commit
e89483d612
13 changed files with 487 additions and 113 deletions
|
@ -10,7 +10,7 @@ using UnityEngine.AI;
|
|||
public class HardObstacle : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float lifeTime = -1.0f; //Time before self-destruct (Negative value to prevent self-destruct)
|
||||
float lifeTime= -1.0f, waitTime= 30.0f; //Time active/waiting before self-destruct (Negative value to prevent self-destruct)
|
||||
float lifeTimer;
|
||||
|
||||
List<Client_controller> angryClients = new List<Client_controller>(); //Clients in the fight
|
||||
|
@ -25,7 +25,7 @@ public class HardObstacle : MonoBehaviour
|
|||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
lifeTimer=lifeTime;
|
||||
lifeTimer=waitTime; //Start by waiting client
|
||||
|
||||
ObsCollider = GetComponent<Collider2D>();
|
||||
|
||||
|
@ -39,14 +39,10 @@ public class HardObstacle : MonoBehaviour
|
|||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if(animator.GetBool("active fight") && lifeTimer>0)
|
||||
{
|
||||
lifeTimer -= Time.deltaTime;
|
||||
if(lifeTimer<0)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
lifeTimer -= Time.deltaTime;
|
||||
if(lifeTimer<0)
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
|
@ -54,21 +50,25 @@ public class HardObstacle : MonoBehaviour
|
|||
Client_controller newClient = other.GetComponent<Client_controller>();
|
||||
if(newClient!=null && !angryClients.Contains(newClient))
|
||||
{
|
||||
angryClients.RemoveAll(item => item == null); //In case clients have been destroyed before event start, remove them
|
||||
|
||||
if(newClient.status!="event") //Make sure to set right status
|
||||
newClient.assignToEvent(gameObject.transform.position);
|
||||
angryClients.Add(newClient);
|
||||
|
||||
// Debug.Log("New fighting client. Current nb : "+angryClients.Count);
|
||||
|
||||
if(angryClients.Count>1)//Start fight
|
||||
{
|
||||
foreach(Client_controller client in angryClients) //Turn off client (to merge for a fight)
|
||||
client.gameObject.SetActive(false);
|
||||
client.gameObject.SetActive(false);
|
||||
|
||||
animator.SetBool("active fight", true);
|
||||
|
||||
|
||||
//Block movement
|
||||
Obstacle.enabled=true;
|
||||
ObsCollider.isTrigger=false; //Trigger becoming solid
|
||||
|
||||
lifeTimer=lifeTime; //Time before end of the fight
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class HardObstacle : MonoBehaviour
|
|||
client.assignToEvent(); //Restore previous behavior
|
||||
}
|
||||
|
||||
EventManager.Instance.destroyEvent(gameObject);
|
||||
EventManager.Instance.removeEvent(gameObject);
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue