What reason could there be, if a parent object refuses to take the new given position?
I am trying to reposition the enemy at the new position at the end of the animation. (It's parent atleast. The child can use this code no problem. It changes to the position I need it to be. Howeverm the parent refuses to do it. Sometimes it does flash to the point I want it to be. But when I watch the X,Y coordinates while testing, the values always stay the same from the beginning of the animation. Could somebody point me out what I am missing about the parents behaviour?
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
scr_eai_kr = animator.gameObject.transform.parent.gameObject.GetComponent<EnemyAI_Kraehe>();
scr_aids_kr = animator.gameObject.transform.parent.gameObject.GetComponent<AIDestinationSetter_Kraehe>();
if (scr_eai_kr.facingRight)
{
/*var otherPosition = new Vector3(1300, 270, 0);
// Will correctly change the transform
animator.gameObject.transform.parent.position = animator.gameObject.transform.parent.position - otherPosition;
Debug.Log("Repositioning Bird to the right.");*/
/*scr_aids_kr.self_target.position = new Vector2(scr_aids_kr.self_target.position.x + 1300, scr_aids_kr.self_target.position.y - 270);
Debug.Log("Repositioning Bird to the right.");*/
var parentPosition = animator.gameObject.transform.parent.gameObject.GetComponent<Transform>();
Debug.Log("Current Position: " + parentPosition);
var newPosition = new Vector2(parentPosition.position.x + 1300, parentPosition.position.y - 270);
parentPosition.position = newPosition;
Debug.Log("New Position: " + newPosition);
}
else if (!scr_eai_kr.facingRight)
{
scr_aids_kr.self_target.position = new Vector2(scr_aids_kr.self_target.position.x - 1300, scr_aids_kr.self_target.position.y - 270);
Debug.Log("Repositioning Bird to the right.");
}
}
Many Thanks -Koda
Your answer
Follow this Question
Related Questions
How too climb a ladder with the FPS Controller correctly 0 Answers
OVR Walking Animation trigger. 0 Answers
[C#]How to save a list of items to use in another script and it's not a player prefs type of list? 0 Answers
Why can't I call a function within the same class? (Or: how does unity handle instancing?) 0 Answers
How to have a trigger activate animation on another game object. 2 Answers