1.Script de la balle qui spawn:
Code : Tout sélectionner
public float maxDistance = 1000000;
RaycastHit hit;
public GameObject decalHitWall;
public float floatInfrontOfWall;
public GameObject bloodEffect; /*pour effet de sang*/
public LayerMask ignoreLayer;
private GameObject corps;
private GameObject tete;
void Start()
{
corps = GameObject.FindGameObjectWithTag("Dummie"); /*Tag présent sur l'ennemie*/
tete = GameObject.FindGameObjectWithTag("Tete"); /*Tag présent sur la tete de l'ennemie pour tirer dans la tete*/
}
void Update() {
if (Physics.Raycast(transform.position, transform.forward, out hit, maxDistance, ~ignoreLayer)) {
if (decalHitWall) {
if (hit.transform.tag == "LevelPart") {
Instantiate(decalHitWall, hit.point + hit.normal * floatInfrontOfWall, Quaternion.LookRotation(hit.normal));
Destroy(gameObject);
}
if (hit.transform.tag == "Dummie") {
Instantiate(bloodEffect, hit.point, Quaternion.LookRotation(hit.normal));
[highlight=yellow]perteVieCorps(50);[/highlight]
Destroy(gameObject);
}
if (hit.transform.tag == "Tete"){
Instantiate(bloodEffect, hit.point, Quaternion.LookRotation(hit.normal));
[highlight=yellow]perteVieCorps(100);[/highlight]
Destroy(gameObject);
}
}
Destroy(gameObject);
}
[highlight=yellow]void perteVieCorps (int parametre){
corps.GetComponent<zombieAI>().vie -= parametre;[/highlight]
}
Destroy(gameObject, 0.1f); /*detruit la balle*/
}
}
2.le script de l'ennemie:
Code : Tout sélectionner
[b] public int vie = 100;[/b]
NavMeshAgent nm;
private Transform player;
private Animator animator;
public Rigidbody[] ragdollRigibodies;
void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
nm = GetComponent<NavMeshAgent>();
animator = GetComponentInChildren<Animator>();
ragdollRigibodies = GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody rb in ragdollRigibodies)
{
rb.isKinematic = true;
}
}
void Update()
{
nm.SetDestination(player.position); /*pour que l'ennemie se dirige vers le joueur*/
[b] if (vie <= 0) //
{
animator.enabled = false;
Dead();
}
void Dead() {
foreach (Rigidbody rb in ragdollRigibodies)
{
rb.isKinematic = false; /*ennemie devient moue*/
}
Destroy(gameObject, 15); /*destruction de l'ennemie qui se trouve par terre*/
}[/b]
Merci encore, n’hésiter pas de me poser des questions.