Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Animatiion not triggering?

Discussion in 'Scripting' started by OXYGEN, Aug 25, 2008.

  1. OXYGEN

    OXYGEN

    Guest

    Joined:
    Mar 16, 2008
    Posts:
    1,101
    Hi guys my animation is not triggering when i press my gui button no errors appear so i asume its finding the anims but it just does not trigger?

    relevant part of code below
    [/code]

    var musicdoor : GameObject;
    var button1turnoff : GameObject;
    var button2turnoff : GameObject;


    public var highlightTexture : Texture2D;
    private var originalTexture : Texture2D;

    public function OnMouseEnter () : void
    {
    originalTexture = GetComponent (typeof (GUITexture)).texture;
    GetComponent (typeof (GUITexture)).texture = highlightTexture;

    }

    public function OnMouseExit () : void
    {
    GetComponent (typeof (GUITexture)).texture = originalTexture;
    }

    function OnMouseDown () //: void

    {
    //musicdoor.animation.wrapMode = WrapMode.Clamp;

    GetComponent (typeof (GUITexture)).texture = originalTexture;

    audio.Play();
    musicdoor.animation.wrapMode = WrapMode.Clamp;
    musicdoor.animation.CrossFade("doorcode",0.5);button1turnoff.layer = 2;//thesearethegameobjectand its hitraycastlayer
    button2turnoff.layer = 2;

    return;
    }

    Code (csharp):
    1.  
     
  2. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    try calling

    Code (csharp):
    1.  
    2. musicdoor.animation.Play();
    3.  
    In your OnMouseUp() function or down.

    Edit: Oops sorry didnt see the CrossFade call. Is the string name for the animation correct ("doorcode")?
     
  3. OXYGEN

    OXYGEN

    Guest

    Joined:
    Mar 16, 2008
    Posts:
    1,101
    string seems to be fine is there something wrong with the way im calling the variable?

    also created a test anim and a new function in unity to check whether it was something to do with the imported object or the mousedown code i created but even with the new script its not working any ideas
    no errors flag up so i asumeing its finding the Gameobject and its animation but its just not playing it

    Code (csharp):
    1.  
    2. var musicdoor : GameObject ;
    3.  
    4.  
    5. function Update () {
    6. if (Input.GetKey("z"))  
    7.    
    8.     musicdoor.animation.CrossFade("New Animation 1", 0.5);
    9.  
    10.   }
    11.  
     
  4. OXYGEN

    OXYGEN

    Guest

    Joined:
    Mar 16, 2008
    Posts:
    1,101
    not sure what the issue was but after renameing the object and then reassighning it. got it to work not sure why? if it was a Syntax im asumeing it would of flagged a error message !! might be a syntax! or perhaps the Unity elves!! either one Im happy


    cheers Marc for your input
     
  5. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    If you have another animation regularly playing, it'll override the crossfade.

    Is the crossfade the only animation call going at the time? (I.E. Do you have any animations being called in Update)