Search code examples
unity-game-engineunityscript

Animation looping although Loop Time is unchecked


#pragma strict

var anim : Animator;

function Start () {
    anim = GetComponent("Animator");

  }    

function Update () {    
    if (Input.GetButtonDown("Fire1")) 
    {
        anim.SetFloat("hit",1);      
    }
}

I have set 'hit' float parameter with 'attack' state, if value of 'hit' > 0.1 , then make transition to 'attack' state from 'Idle state'.

Now problem is, when i click mouse left button, the transition goes from Idle to 'attack' and model perform the desired task, then transition goes from 'attack to Idle' and then again transition goes 'Idle to attack' and goes in loop.

I have set LoopTime, Loop poseto unchecked in animationClip, but still the same is happening.

I understand, the above goes in loop, because the 'hit' parameter never becomes < 0.1 so everytime the condition gets true and transition happens to attack state.

If i add the below line to the above Update() function , then transition never happens.

anim.SetFloat("hit",0);

I dont know where is the problem, what should i do ??, i want when i click mouse left button, then model should hit once and then goes back to Idle state, then again if i click mouse left click, then only it should it..

Any help ?? Please

Thanks in advance


Solution

  • you can use trigger for things that happens once and then they should get back to the state they came from like hitting or jumping or etc

    anim.SetTrigger("hit");