# Unity Scripting

Unity Scripting is done with C# scripts. All realvirtual.io functionality is done based on C# Scripting. The possibilities are endless. As an editor you need to have a C# editor like Visual Studio or Rider installed. You can find a lot of information about C# and C# scripting on the Internet. For a full documentation of the Unity API please go to this page:

{% embed url="<https://docs.unity3d.com/Manual/ScriptingSection.html>" %}

If you are already a programmer you might prefer to use C# scripts instead of the visual scripting approaches like [Logicsteps](/components-and-scripts/defining-logic/logicsteps.md), [Unity Visual Scripting](/components-and-scripts/defining-logic/unity-visual-scripting.md) or [https://github.com/game4automation/doc/blob/doc/components-and-scripts/defining-logic/broken-reference/README.md](https://github.com/game4automation/doc/blob/doc/components-and-scripts/defining-logic/broken-reference/README.md "mention").

## Installation of Visual Studio, Rider or another Scripting environment

Before scripting in C# you need to install Visual Studio or Rider. Please check the documentation on the Unity website about installing Visual Studio:

{% embed url="<https://docs.unity3d.com/Manual/VisualStudioIntegration.html>" %}

{% hint style="info" %}
Please make sure, that your scripting environment is linked as external tool like shown below:
{% endhint %}

<figure><img src="/files/JGOY0Ixxp9y5Gs8Emplz" alt=""><figcaption></figcaption></figure>

## Scripting realvirtual.io with C\#

Most important thing is, if you wan to use realvirtual.io classes and properties, to embed it by putting this using in front of your code (or alternatively put your code into the

`using game4automation;`

Here is a small example of a PLC like script for controlling a Drive based on a Sensor:

```csharp
    using realvirtual;
    using UnityEngine;
    
    //! PLC Script for the game4automation demo model
    public class PLC_CanConveyor : ControlLogic
    {
        public bool On = true;

        [Header("References")] public PLCOutputBool StartConveyor;
        public PLCInputBool SensorOccupied;
        public PLCInputBool ButtonConveyorOn;
        public PLCOutputBool LampCanAtPosition;

        // Call this when all Updates are done
        void FixedUpdate()
        {

            if (SensorOccupied.Value == false && On && ButtonConveyorOn.Value == true)
            {
                StartConveyor.Value = true;
            }
            else
            {
                StartConveyor.Value = false;
            }

            LampCanAtPosition.Value = SensorOccupied.Value;
        }
    }

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.realvirtual.io/components-and-scripts/defining-logic/unity-scripting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
