---
# System prepended metadata

title: ROS-UNITY-ZED Guide

---

ROS-UNITY-ZED Guide
===

1. Use Unity _2021.3.11f1_  , than install the latest Zed  Plugin file from   stereo labs.


## Script Basics


### Mono Behaviour

A script makes its connection with the internal workings of Unity by implementing a class which derives from the built-in class called MonoBehaviour. You can think of a class as a kind of blueprint for creating a new Component type that can be attached to GameObjects. Each time you attach a script component to a GameObject, it creates a new instance of the object defined by the blueprint. The name of the class is taken from the name you supplied when the file was created. The class name and file name must be the same to enable the script component to be attached to a GameObject.

The main things to note, however, are the two functions defined inside the class. The Update function is the place to put code that will handle the frame update for the GameObject. This might include movement, triggering actions and responding to user input, basically anything that needs to be handled over time during gameplay. To enable the Update function to do its work, it is often useful to be able to set up variables, read preferences and make connections with other GameObjects before any game action takes place. The Start function will be called by Unity before gameplay begins (ie, before the Update function is called for the first time) and is an ideal place to do any initialization.


**Note to experienced programmers: you may be surprised that initialization of an object is not done using a constructor function. This is because the construction of objects is handled by the editor and does not take place at the start of gameplay as you might expect. If you attempt to define a constructor for a script component, it will interfere with the normal operation of Unity and can cause major problems with the project.**


### SerializeField


Force Unity to serialize a private field. **They allow private variables to show and be edited in the Inspector.**
When Unity serializes your scripts, it only serializes public fields. If you also want Unity to serialize your private fields you can add the SerializeField attribute to those fields.

Unity serializes all your script components, reloads the new assemblies, and recreates your script components from the serialized versions. This serialization is done with an internal Unity serialization system; not with .NET's serialization functionality.


Unity can serialize fields of the following types:

All classes inheriting from UnityEngine.Object, for example GameObject, Component, MonoBehaviour, Texture2D, AnimationClip.
All basic data types, such as int, string, float, bool.
Some built-in types, such as Vector2, Vector3, Vector4, Quaternion, Matrix4x4, Color, Rect, LayerMask.
Arrays of a serializable type
Lists of a serializable type
Enums
Structs

### Important Classes 

#### Time

* Time.time returns time elapsed since project started.

* Time.deltaTime returns the amount of time in seconds that elapsed since the   last frame completed. This value varies depending on the frames per second
 (FPS) rate at which your game or app is running.
 
 
#### Important Classes - MonoBehaviour

SWITCH TO SCRIPTING
The MonoBehaviour class is the base class from which every Unity script derives, by default. When you create a C# script from Unity’s project window
, it automatically inherits from MonoBehaviour, and provides you with a template script. See Creating and Using scripts for more information on this.

The MonoBehaviour class provides the framework which allows you to attach your script to a GameObject
 in the editor, as well as providing hooks into useful Events such as Start and Update.

For a complete reference of every member of the MonoBehaviour class, and its technical details, see the MonoBehaviour script reference.

Coroutines
The MonoBehaviour class allows you to start, stop, and manage Coroutines, which are a way to write asynchronous code which can include waiting for a certain amount of time, or for certain actions to complete, while allowing other code to continue executing.

For more information about coroutines, see the Coroutines manual page and the StartCoroutine method script reference.

**Events**

**The MonoBehaviour class provides access to a large collection of event messages, which allows you to execute your code based on what is currently happening in your project. Here are a few of the more common examples. For a list of them all, see the Messages section on the MonoBehaviour script reference page**

```
Start - called when the GameObject begins to exist (either when the Scene is loaded, or the GameObject is instantiated).

Update - called every frame.

FixedUpdate - called every physics timestep.

OnBecameVisible and OnBecameInvisible - called when a GameObject’s renderer enters or leaves a camera
’s view.

OnCollisionEnter and OnTriggerEnter - called when physics collisions
 or triggers occur.

OnDestroy - called when the GameObject is destroyed

```

### Order of Execution for Event Functions




