Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

change object's rotation inside animation window via script?

Discussion in '2D' started by PersianKiller, Feb 24, 2018.

  1. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    114
    is it possible to change an object's rotation inside animation window via script?? for example I want to change left-hand's rotation at frame 6 to -40,but via script.not inside animation window.

    my character can pick lot's of items,some of them need his hand to rotate a lot and others need less rotate.can someone help me with this? i don't want to create lot's of animations to handle it.
     

    Attached Files:

  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    You can use animation events that are triggered from within the animation. Right click on the time line and choose Add Animation Event. Then, you can choose to trigger a public method on your object.
     
    PersianKiller likes this.
  3. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    114
    very good idea,thanks alot :)
     
  4. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    114
    @PGJ ,now i'm using an animation event at frame 0 it sets hand's position and rotation.(for every gun).

    for example when i pick a gun it sets position and rotation of the hand.but at frame 0,how can I change rotation for example at frame 6? i mean when I pick a gun, rotation at frame 0 is 10,I want it to be 50 at frame 6,and hand should rotates from frame 0 to 6??? i'm using this because every gun has a different rotation between frame 0 to 6 and I have no idea how to do it :)










     
  5. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    Is your gun just following the hand? Can't you just set it as a child of the hand, then it will follow the hand as it animates. Or am I missing something?
     
  6. PersianKiller

    PersianKiller

    Joined:
    Jul 16, 2017
    Posts:
    114
    it's a 2d game.
    when i pick a gun,it will be child of the hand ,yes,but I want to rotate the hand not the gun,so when i have a colt ,player has an idle animation and his hand rotation should be 0 at frame 0 and it should be 50 at frame 6,if i pick a M16 his hand rotation should be 25 at frame 0 and it should be 40 at frame 6,so i need a function to rotate his hand i just don't know how to set min and max rotation for this function.

    https://forum.unity.com/attachments/untitled-png.267895/

    as you can see in this image if i could use a variable and just change it's value to change rotation it will solve all the problems :)