Search Unity

Click on a object and a animation will start HELP!

Discussion in 'Scripting' started by GerryHmm, Sep 20, 2014.

  1. GerryHmm

    GerryHmm

    Joined:
    Sep 20, 2014
    Posts:
    1
    Hello i need some help.
    When i Click on a object i want a animation to start. if you know how to do please reply i would appriciate that. thanks
     
    Last edited: Sep 21, 2014
  2. MysterySoftware

    MysterySoftware

    Joined:
    Sep 18, 2014
    Posts:
    46
    Hey, you could use this small script to create a ray from your mouse cursor and check what/if it hits something.

    Code (JavaScript):
    1. var hit : RaycastHit;
    2. var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    3.  
    4. if (Physics.Raycast (ray, hit)) {
    5.     // Do something here. Start your animation or something
    6. }