using System.Collections;
using System.Collections.Generic;
using UnityEngine;

 public class Clique_vitre : MonoBehaviour {
    private Animator Anim;     private int swt = 0;
    private AnimatorStateInfo animationState;
    private AnimatorClipInfo[] myAnimatorClip;

    void Start()     {      
     Anim = transform.parent.parent.GetComponent<Animator>();        
    }

    void OnMouseDown()
    {
       
        animationState = Anim.GetCurrentAnimatorStateInfo(1);///doit être redéfinit à chaque fois car clip change...  
        float myTime = Mathf.Abs(1 - animationState.normalizedTime);        
        if (animationState.normalizedTime > 1) myTime = 0;////si animation termine et donc plus loin que 1, animation doit rewind
        if (swt == 0)         {
            Anim.Play("vitre_ouvre", 1, myTime);

            swt = 1;         }
        else
        {
            swt = 0;
            Anim.Play("vitre_ferme", 1, myTime);
        }
    }
  }