Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Problems with Raycast in C#

Discussion in 'Scripting' started by Rhyusaky, Mar 21, 2016.

  1. Rhyusaky

    Rhyusaky

    Joined:
    Jan 22, 2016
    Posts:
    25
    Hello, can someone help me, whenever I do this Raycast in Unity, appear the error CS1502 and CS1503 saying:
    In the first error: The best overloaded method match for 'UnityEngine.Physics.Raycast (UnityEngine.Vector3, UnityEngine.Vector3, float, int)' has some invalid arguments
    And the second: Argument # 2 '' can not 'convert method group' expression to type `UnityEngine.Vector3 '
    And here's the code:
    Code (CSharp):
    1. if (Physics.Raycast(transform.position, MainCamera.ScreenPointToRay, out Position, 100.0f))  {
    2.  
    3. }
    Alguem pode me ajudar?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

    you're not passing the correct parameters, specifically there isn't one that takes a (vector3, ray, <whatever Position is>, float)

    that page lists all of the acceptable overloads of the raycast function.

    You are most likely after the second one listed: (vector3 position, vector3 direction, raycasthit, float)
     
  3. Rhyusaky

    Rhyusaky

    Joined:
    Jan 22, 2016
    Posts:
    25
    Something like?
    Code (CSharp):
    1. if (Physics.Raycast(transform.position, out Position,  MainCamera.ScreenPointToRay, 100.0f))
     
  4. SubZeroGaming

    SubZeroGaming

    Joined:
    Mar 4, 2013
    Posts:
    1,008
    watch my youtube video on raycasting.