Commit 54d1d6fc authored by DUMOULIN ANTOINE's avatar DUMOULIN ANTOINE
Browse files

Merge branch 'bugfix/clous' into 'develop'

Bugfix/clous

See merge request fauchezlegouic/projet-integrateur!402
parents aae09f74 d9f81ef7
......@@ -12,7 +12,7 @@ public class StopAnimationTrap : MonoBehaviour
}
void OnCollisionEnter(Collision infoCollision)
{
if (infoCollision.gameObject.tag == "TerrainBeton" || infoCollision.gameObject.tag == "tremplin")
if (infoCollision.gameObject.CompareTag("TerrainBeton") || infoCollision.gameObject.CompareTag("tremplin") || infoCollision.gameObject.CompareTag("TerrainSand"))
{
rb.isKinematic = true;
......
......@@ -14,72 +14,33 @@ public class TrapDetection : MonoBehaviour
public GameObject clous;
private Collider[] _boxColliders;
private Rigidbody[] _rigidbody;
PlayerController player = null; // Le joueur
private UIController _UiDisp = null; // Pour l'affichage dans l'UI
//private float _pourcentDamage = 0.10f; // Pourcentage de dégat par le piège
internal float _secSlowDown = 2f; // Durée en seconde du slow down
public float activationDelay = 1.5f;
private float _activationStart;
private float _activation;
private GameObject _player; // Le joueur
public float activationDelay = 1.4f;
private void Awake()
{
_activation = Time.time + activationDelay;
_UiDisp = FindObjectOfType<UIController>();
StartCoroutine(ActivationDelay());
GameObject [] players = GameObject.FindGameObjectsWithTag("Player");
foreach (var p in players)
{
if (p.GetComponent<PlayerController>())
_player = p;
}
_boxColliders = clous.GetComponentsInChildren<Collider>();
_rigidbody = clous.GetComponentsInChildren<Rigidbody>();
foreach (var r in _rigidbody)
{
r.isKinematic = true;
}
foreach (var c in _boxColliders)
{
c.enabled = false;
}
clous.SetActive(true);
StartCoroutine(ActivationDelay());
}
IEnumerator ActivationDelay()
{
_activationStart = Time.time;
float x = clous.transform.position.x;
float y = clous.transform.position.y;
while (Time.time - _activationStart < activationDelay)
clous.transform.position = _player.transform.position;
yield return new WaitForSeconds(activationDelay);
foreach (var c in _boxColliders)
{
yield return new WaitForSeconds(0.05f);
clous.transform.Translate(0, -0.05f, 0);
c.enabled = true;
}
foreach (var r in _rigidbody)
{
r.isKinematic = false;
}
foreach (var c in _boxColliders)
{
c.enabled = true;
}
}
IEnumerator SlowDownCoroutine()
{
player.SetSlowDown(true);
yield return new WaitForSeconds(_secSlowDown);
player.SetSlowDown(false);
Destroy(gameObject);
}
/**
* Détecte la collision entre le piège et un véhicule.
* @param Collider other: collider du joueur qui a fait une collision avec l'objet
*/
// void OnTriggerEnter(Collider other) {
// if(_activation < Time.time && other.transform.root.CompareTag("Player"))
// {
// // Pour éviter que le piège n'attaque plusieurs fois
// gameObject.GetComponent<BoxCollider>().enabled = false;
// // Pour le faire disparaître
// gameObject.GetComponentInChildren<Renderer>().enabled = false;
// _UiDisp.Damage((int)(_UiDisp.GetMaxLife()*_pourcentDamage));
// player = other.transform.root.gameObject.GetComponent<PlayerController>();
// StartCoroutine(SlowDownCoroutine());
// }
// }
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment