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. Dismiss Notice

js to c#

Discussion in 'Scripting' started by MODEEEEE, Jun 19, 2014.

  1. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    How to convert this:
    var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
    if(Physics.Raycast(ray, hit))
    {
    in to c#?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    add new in front of Vector3
     
  3. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    js implicitly does the out thing for you, so add out in front of hit param.
     
  4. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Code (csharp):
    1. var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
    2. if(Physics.Raycast(ray, out hit))
     
  5. Erisat

    Erisat

    Joined:
    Jan 31, 2013
    Posts:
    88
    ive used this before. takes some further tweaking afterwards, but i find that when converting scripts it does quite a bit of the legwork for you, and saves me time personally. http://www.m2h.nl/files/js_to_c.php
     
  6. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    Thanks!! and what about this one?
    var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
     
  7. Erisat

    Erisat

    Joined:
    Jan 31, 2013
    Posts:
    88
    Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
     
  8. Erisat

    Erisat

    Joined:
    Jan 31, 2013
    Posts:
    88
    what happens when you run the script? do you get errors?
     
  9. MODEEEEE

    MODEEEEE

    Joined:
    Feb 15, 2014
    Posts:
    52
    I solved it :) the problem is that i Sended message to a js script not c#