Search Unity

[C#] Why does my chest-close-animation not play?

Discussion in 'Scripting' started by ande04b, Jul 25, 2015.

  1. ande04b

    ande04b

    Joined:
    Aug 29, 2012
    Posts:
    119
    Hey people :)

    I have b een working on this chest script, and it works 90%, as the "open" animation plays when my player is in range, and clicks his right mouse button. The "open" animation then plays in reverse (effectively a close animation) when the chest is open and the player walks out of range, but if the chest is open, and the player right-clicks the chest, it should also play the reverse "open" animation - but it doesn't.

    Can anyone enlighten me on why it doesn't? :)

    Link to the script:
    http://pastebin.com/Q9WKe0e5

    I know things could probably be optimized in the script - I'm not very good of a programmer, so bear with me ;)

    Thanks in advance the the help guys :)
     
  2. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    plenty of open-close doors tutorials on YouTube...can easy be adapted to open-close chest
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    you set the speed back to 1 in the same frame on line 114...
     
    ande04b likes this.
  4. ande04b

    ande04b

    Joined:
    Aug 29, 2012
    Posts:
    119
    @herman111
    I'm sorry, but it's so annoying when asking some question on a forum, someone turns up stating "Look up a tutorial".
    I know there are tons of tutorials out there, but I want to make my own scripts and incorporate as little copy/pasting as possible. I know I could have just watched a tutorial and see how other people are doing it, but I want to use my brain.
    And surely enough, I didn't need a tutorial, since the error is, like @LeftyRighty said, in Line 114. Something you could have noticed, had you just cared enough to make a good answer, if you had actually looked at the code you are commenting on.

    @LeftyRighty
    thank you, this fixed it obviously. :) Sometimes you can stare yourself blind on your code, and having others look it over often reveals issues like this :)
    You have my gratitude.
     
  5. herman111

    herman111

    Joined:
    May 11, 2014
    Posts:
    119
    sorry for the answer, that's what people tell me to do...I'm looking for answers to my problem posted on here.I look at other scripts and do change them for my purpose
     
    phoda likes this.