Trying to do a script to stun temporarily

Hi,
So I’m a beginner in CSharp, and I have to do a game for school. I wanted one of my projectiles to stun the enemy. So I’ve managed to do that, the stunning part actually works, but there is a problem I can’t seem to solve by myself : I want the enemy to be temporarily stunned only. A friend of mine tried to help, but, I don’t know why, it doesn’t work : the object receiving the projectile is stunned and doesn’t regain his movements. The problem is, I’m unable to continue this script, since I don’t understand what my friend tried to do regarding the part of the script written to make it temporary.

using UnityEngine;
using System.Collections;

public class TentativeStun : MonoBehaviour {


    public Behaviour move;
    public GameObject missile;
    public float tempsStun = 1f;
    public float tempSecondes = 1f;
    public bool touche = false;
    public float duréeStun = 0f;



    // Use this for initialization
    void Start ()
    {
        duréeStun = tempsStun;
    }
   
    // Update is called once per frame
    void OnTriggerEnter (Collider other)
    {
        if (other.gameObject.tag == "stun")
        {
            move.enabled=false;
            touche = true;
            Debug.Log ("Il y a eu collision");

        }

    }
    void Update ()
    {
        if (touche == true)
        {
            if (duréeStun)
            Debug.Log ("On est dans le if touche");
            touche = false;
            returnattente();
            Debug.Log ("Le move est retabli");
            move.enabled = true;
            tempsStun = duréeStun;
            tempSecondes = 0;
        }

       

    }

    //Here is what my friend did, so I don't understand anything...

    IEnumerator attente ()
    {
        yield return new WaitForSeconds (3);
    }

    void returnattente ()
    {
        yield return attente;
    }

}

Sorry for my variables’ names are in French, I can rename them in necessary.
Thanks.

Hi,
There are a couple ways of stunning something, and it also depends on your definition of stun. Let me list off the ways.

You can use IEnumerator’s to yield the script, which will halt the script for 3 seconds like your friend did.

You could isolate your script into a void, so it will only cycle through one void until a variable reaches true (in this case until the time stunned has been reached).

Hope this helped a little.
-Moon

Under the Update function it doesn’t look like anything counts up the stun duration, so ‘duréeStun’ never becomes true (and is missing the brackets for it).
It doesn’t look needed, so you could try removing that part and moving the returnattente(); function up to where it was.
Something like this:

    void Update ()
    {
        if (touche == true)
        {
            returnattente();
            Debug.Log ("On est dans le if touche");
            touche = false;
            Debug.Log ("Le move est retabli");
            move.enabled = true;
            tempsStun = duréeStun;
            tempSecondes = 0;
        }
    }

I’m not entirely sure what purpose some of this code serves so I’m not game to change too much.

Thank you very much for your answers, I finally managed to make my script function.

Good to hear. =)