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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2D follow mouse script help!

Discussion in 'Scripting' started by lionbear, Apr 24, 2015.

  1. lionbear

    lionbear

    Joined:
    Mar 22, 2011
    Posts:
    12
    i have this script that i was following on youtube to get a feel for scripting.


    i used this code
    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var myCamera : Camera;
    4.  
    5. function Start () {
    6.  
    7. }
    8.  
    9. function Update () {
    10.     var vec : Vector3 = myCamera.ScreenToWorldPoint(Input.mousePosition);
    11.     vec.x = 0.0;
    12.     transform.position = vec;
    13. }
    the left and right works good but up and down is back words:( how can i fix this?.
     
  2. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    990
    Try adding vec.y = vec.y * -1; See if this works!
     
    lionbear likes this.
  3. lionbear

    lionbear

    Joined:
    Mar 22, 2011
    Posts:
    12
    thank you it works:)