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

I don't know how to set a gameObject as a target.

Discussion in 'Scripting' started by Ghosts_Riley, Jan 18, 2014.

  1. Ghosts_Riley

    Ghosts_Riley

    Joined:
    Dec 7, 2013
    Posts:
    82
  2. Ghosts_Riley

    Ghosts_Riley

    Joined:
    Dec 7, 2013
    Posts:
    82
  3. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    Do you see those variables declared near the top with "public (inserttypehere) (insertnamehere)"? Those you can "edit" from the Inspector window when you click on the GameObject with the script on it. Just click on the GameObject, scroll down until you see the script, and if it isn't open, open that component (the script).

    Now, you'll see the field for the target variable as empty. All you have to do now is drag the other GameObject from the hierarchy into that slot. Done!
    (Yes, don't click, wait, then drag the other object. The inspector will change then. Do a quick drag.)
     
  4. Ghosts_Riley

    Ghosts_Riley

    Joined:
    Dec 7, 2013
    Posts:
    82
    Thank you very much!
     
  5. Ghosts_Riley

    Ghosts_Riley

    Joined:
    Dec 7, 2013
    Posts:
    82
    It doesn't work because of my code... I think.
    Here is my code.
    I think it's the layerMask
    Here are my errors.
    Assets/Scripts/RaycastExample.cs(24,110): error CS0103: The name `layerMask' does not exist in the current context
    Assets/Scripts/RaycastExample.cs(23,29): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit, float, int)' has some invalid arguments
    Assets/Scripts/RaycastExample.cs(23,29): error CS1503: Argument `#5' cannot convert `object' expression to type `int'


    $Screen Shot 2014-01-18 at 3.08.12 PM.png
     
  6. Ghosts_Riley

    Ghosts_Riley

    Joined:
    Dec 7, 2013
    Posts:
    82
    I can't seem to figure it out. I've been here for 4 hours trying to figure it out. Please help someone.