title: Modify x position of Gameobject while playing an animation - Unity
body: <p>I have a gameobject with an animator controller. The gameobject moves from the bottom of the screen to the top, this movement is being controlled by the animation of th Y axis.</p>
  
  <p>What i am trying to do is to also move it randomly in the X axis While the this animation is moving it in the Y axis</p>
  
  <p>What i did was to set a few animation events in this main animation:</p>
  
  <p><a href="https://i.stack.imgur.com/213yc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/213yc.png" alt="enter image description here"></a></p>
  
  <p>In this events i am calling a script that moves the object between 2 x positions:</p>
  
  <pre><code>public void RandomX ()
  {
      var pos = transform.position;
      pos.x =  Mathf.Clamp(transform.position.x, -1.75f, 2.85f);
      print(pos.x);
  }
  </code></pre>
  
  <p>But this is not working. Tha animation plays with no modifications in the X axis.</p>
  
  <p>Thanks in advance for any help provided</p>