How to start C# script during gameplay?

Using Naninovel C# APIs: adding custom actor implementations or commands, overriding engine services, integrating with other systems, etc.
Post Reply
VarBet
Posts: 6
Joined: 02 Oct 2022 22:08

How to start C# script during gameplay?

Post by VarBet »

I'm trying to run my C# script, but for it to load only during gameplay (e.g after clicking on New Game, or Continue). Is this possible?

Basically, run a C# script as soon as game enters the gameplay

VarBet
Posts: 6
Joined: 02 Oct 2022 22:08

Re: How to start C# script during gameplay?

Post by VarBet »

I'm trying to run my C# script, but for it to load only during gameplay (e.g after clicking on New Game, or Continue). Is this possible?

Basically, run a C# script as soon as game enters the gameplay

Some simple C# script that I need for it to start in gameplay mode

Code: Select all

using System.Collections;
using System.Collections.Generic;
using Naninovel;
using UnityEngine;

public class Clock : MonoBehaviour
{
    string Date_Month;
    string Date_Day;
    string Date_Time_Hours;
    string Date_Time_Minutes;
    string Date_Time_Seconds;

// Start is called before the first frame update
void Start()
{
    Debug.Log("Started on gameplay");
}

// Update is called once per frame
void Update()
{

}
}
idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: How to start C# script during gameplay?

Post by idaot »

Consider using the OnStart and OnStop events in IScriptPlayer. https://naninovel.com/guide/engine-serv ... e-services

VarBet
Posts: 6
Joined: 02 Oct 2022 22:08

Re: How to start C# script during gameplay?

Post by VarBet »

idaot wrote: 16 Oct 2022 08:28

Consider using the OnStart and OnStop events in IScriptPlayer. https://naninovel.com/guide/engine-serv ... e-services

I've looked through the post up and down, I see no reference to a OnStart and OnStop events anywhere

And I'm still confused on how to implement this

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: How to start C# script during gameplay?

Post by idaot »

As the guide states, there are multiple engine services with which you can interact with, in your case it's IScriptPlayer.cs. Search the codebase for examples where OnStart and OnStop is being used within the engine.

VarBet
Posts: 6
Joined: 02 Oct 2022 22:08

Re: How to start C# script during gameplay?

Post by VarBet »

idaot wrote: 16 Oct 2022 15:27

As the guide states, there are multiple engine services with which you can interact with, in your case it's IScriptPlayer.cs. Search the codebase for examples where OnStart and OnStop is being used within the engine.

I've looked through the link multiple times. Also checked out https://naninovel.com/guide/integration ... ialization

No sign of any OnStart/OnStop event

I've even googled it, and looked through this forum's search box. No results

Elringus
admin
Posts: 521
Joined: 11 May 2020 18:03

Re: How to start C# script during gameplay?

Post by Elringus »

Searching the codebase means using IDE tools to look for something in the source code, not googling or using forums. Most of the public APIs in Naninovel are documented and you can learn a lot by analyzing how they are used internally.

VarBet
Posts: 6
Joined: 02 Oct 2022 22:08

Re: How to start C# script during gameplay?

Post by VarBet »

To be more specific..

-- When making a custom UI and attaching a script onto the UI, how can I make it where the script update is ran only when the UI is "shown" and stop running when "hidden"

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: How to start C# script during gameplay?

Post by idaot »

Use the OnShow() or OnHide() events found on the root of the prefab or listen to the HandleVisibilityChanged event in C#.

Post Reply