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

Resolved checking hits tag/name?

Discussion in 'Visual Scripting' started by enzoravo, Mar 16, 2021.

  1. enzoravo

    enzoravo

    Joined:
    Jun 25, 2013
    Posts:
    284
    hello, i'm trying to do a raycast from my enemy to check if the enemy can see the player, but i can't able to check the tag or name from the result list of hits.

    in c# i did this

    Code (csharp):
    1.    
    2. foreach (RaycastHit hit in hits)
    3. {
    4.     if (hit.transform.tag == "Player")
    5.          Debug.Log("player found");
    6. }
    7.  
    but i'm using this in bolt
    upload_2021-3-16_15-32-30.png

    but when my enemy is trying to check for the player i'm getting this error in the unity editor
    upload_2021-3-16_15-33-53.png

    how can i do this tag check for any of the hit results ?

    thanks in advance for all the help.
     
  2. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi, i don't know Bolt, but the message seems logic. You are testing a RaycastHit in your script without passing it to a gameobject.

    Code (CSharp):
    1. foreach (RaycastHit hit in hits)
    Try to get the gameobject in your foreach :
    Code (CSharp):
    1. GameObject player;
    2.  
    3. foreach (RaycastHit hit in hits)
    4. {
    5.     if (hit.transform.tag == "Player")  player = hit.transform.gameobject;
    6. }
    I hope this helps.
     
  3. enzoravo

    enzoravo

    Joined:
    Jun 25, 2013
    Posts:
    284
    @MlleBun i don't have any problem with the c# code, the problem is with the bolt code, i shown what i used to use in c# to check the tag or the name from the hits result after when i use a raycast but the problem is that bolt didn't return the tag or name using the same code.
     
  4. enzoravo

    enzoravo

    Joined:
    Jun 25, 2013
    Posts:
    284
    got it working, for anyone with this same issue, here is the node to use

    upload_2021-3-16_22-43-17.png
     
    MonoSapiens and MlleBun like this.