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

Question Visual Script to C#

Discussion in 'Visual Scripting' started by steweye, Jul 11, 2023.

  1. steweye

    steweye

    Joined:
    Nov 29, 2022
    Posts:
    14
    Does anybody know how can I turn this graph to pure C#?
    And is there a way to auto convert graphs to C# scripts?
    Thanks everyone.
    vstocsharp.PNG
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    Which part do you need help with?

    I dont know. Did you try googling "<name of your visual scripting tool> unity c# converter"?
    If that doesnt come up with anything, probably not.
     
  3. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    I've never dabbled with VisualScript but I guess it is translated to C# internally.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,082
    ChatGPT (specifically the paid GPT-4 with the Link Reader plugin) can analyze images:

    The image you provided contains a visual script from Unity, which appears to be a flow of actions or events. Unfortunately, the Optical Character Recognition (OCR) result is not very clear, and it seems to have misinterpreted some of the text in the image.

    However, I'll try to provide a general idea of how this could be translated into C# based on the OCR result and my understanding of Unity's API. Note that this might not be accurate due to the unclear OCR result.

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.XR.ARFoundation;
    3.  
    4. public class YourClass : MonoBehaviour
    5. {
    6.     public ARRaycastManager arRaycastManager;
    7.     public UnityEngine.UI.Text debugText;
    8.  
    9.     void Update()
    10.     {
    11.         if (Input.touchCount > 0)
    12.         {
    13.             Touch touch = Input.GetTouch(0);
    14.  
    15.             List<ARRaycastHit> hits = new List<ARRaycastHit>();
    16.             if (arRaycastManager.Raycast(touch.position, hits, TrackableType.Planes))
    17.             {
    18.                 // Do something with the hit results
    19.                 // For example, you can print the hit position to the debug text
    20.                 debugText.text = hits[0].pose.position.ToString();
    21.             }
    22.         }
    23.     }
    24. }
    This script assumes that you have an ARRaycastManager and a Text component attached to your GameObject. It checks for touch input every frame, and if there is a touch, it performs a raycast from the touch position. If the raycast hits a plane, it sets the debug text to the hit position.

    Please replace YourClass with the appropriate class name for your use case. Also, ensure that the arRaycastManager and debugText are assigned in the Unity inspector or via script.

    Remember, this is a very rough translation and might not accurately represent the visual script in the image. You may need to adjust it based on your specific needs and the actual content of the visual script.
     
    CodeSmile and Yoreki like this.