So I'm getting the basics of a platformer going, and doing the work early for animations and actions. I have two animations, DevRollRight and DevAttack, with two StateMachineBehaviours attached to their animation states - DevRollScript and DevAttackScript. I want to access the `transform.localPosition.x` of the Holder (which has the animator on it, and sprites etc as children).
I implemented the DevRollScript a while ago - and when I log the `animator.transform.localPosition.x` during OnStateUpdate, the values I see in the editor are output. Now when I use the same technique on the DevAttackScript, the `localPosition.x` is supposedly 0 every frame (and world position constant), even though when I look in the editor it changes as it is supposed to. What is happening!?
----------
public class DevAttackScript : StateMachineBehaviour
{
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//animator.transform.parent.GetChild(0).gameObject.SetActive(false);
animator.transform.parent.GetComponent().setAttacking(true);
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log(animator.transform.name + "attacky");
Debug.Log(animator.transform.localPosition.x);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//do final stuff
}
}
----------
public class DevRollScript : StateMachineBehaviour
{
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
animator.transform.parent.GetChild(0).gameObject.SetActive(false);
animator.transform.parent.GetComponent().setRolling(true);
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Debug.Log(animator.transform.name + "rolly");
Debug.Log(animator.transform.localPosition.x);
}
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
//final stuff
}
}
----------
![alt text][1]
![alt text][2]
[1]: /storage/temp/157859-holderattacky.png
[2]: /storage/temp/157860-holderrolly.png
Both animations are done in the same way, with unity's keyframes - both of them change the transform.position of Holder. Im at a lost after hours off trying to understand the issue here
↧