0
\$\begingroup\$

I just need to push my game object in y direction not in of its x position,I need to assign it a new position but unable to access its current x position value so that can make it fix on its x position... please help

I tried this:

Vector2 curScreenPoint = new Vector2 (need the current x position of game object , Input.mousePosition.y);
Vector2 curScreenPoint = new Vector2 (0, Input.mousePosition.y);
     Vector2 curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint);
    transform.position = curPosition;

enter image description here

\$\endgroup\$
0
\$\begingroup\$

Not entirely sure what you are trying to accomplish based on your code. Possibly you are not familiar with the MonoBehaviour object type.

Have you tried something like this:

Vector2 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
transform.position = new Vector2(transform.position.x, mousePos.y);
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ actually i have to move an object only in y position not in x,i want to assign the current value of x position while all the movements.. \$\endgroup\$ – Santosh Yadav Jul 14 '15 at 12:16
  • \$\begingroup\$ @SantoshYadav Updated code above. \$\endgroup\$ – jgallant Jul 14 '15 at 12:17
  • \$\begingroup\$ still not working... please have a look on edited problem scenario \$\endgroup\$ – Santosh Yadav Jul 14 '15 at 12:38
  • \$\begingroup\$ @SantoshYadav Updated code again. \$\endgroup\$ – jgallant Jul 14 '15 at 12:41
  • \$\begingroup\$ already tried this before but not getting desired functionality,both slider comes to same position... \$\endgroup\$ – Santosh Yadav Jul 14 '15 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.