Create a script
You can create scripts using Game Studio or an IDE such as Visual Studio.
- In the Asset View, click Add asset > Scripts and select a script type.
Note
For information about different types of script, see .
The New script dialog opens.
Specify a class and namespace for the script and click Create script.
To use the script, you need to save it. By default, Game Studio prompts you to save the script now.
After you save the script, you can see it in the Asset View.
Note
Although scripts are a kind of asset, they're not saved in the Assets folder. Instead, they're saved in the relevant assembly folder. For more information, see Project structure.
Tip
To open your solution in Visual Studio from Game Studio, click the (Open in IDE) icon in the Game Studio toolbar.
- Open Visual Studio.
Tip
To open your solution in Visual Studio from Game Studio, click the (Open in IDE) icon in the Game Studio toolbar.
The game solution is composed of several projects:
The project ending .Game is the main project, and should contain all your game logic and scripts.
Other projects (eg MyGame.Windows, MyGame.Android etc) contain platform-specific code.
For more information, see .
Add a new class file to the project. To do this, right-click the project and select Add > New Item.
The Add New Item dialog opens.
Visual Studio adds a new class to your project.
In the file you created, make sure the script is public and derives from either AsyncScript or SyncScript.
Implement the necessary abstract methods.
For example:
using System;
using System.Text;
using System.Threading.Tasks;
using Xenko.Core.Mathematics;
using Xenko.Input;
using Xenko.Engine;
namespace MyGame
{
public class SampleSyncScript : SyncScript
{
public override void Update()
{
{
// Do something every frame
}
}
}
}
Save the project and script files.
Because you modified the script, Game Studio needs to reload the assembly to show the changes.
Click Yes.
You can see the script in the Asset View.
Note
Although scripts are a kind of asset, they're not saved in the Assets folder. Instead, they're saved in the relevant assembly folder. For more information, see Project structure.