Script player isn't playing anything

Using Naninovel C# APIs: adding custom actor implementations or commands, overriding engine services, integrating with other systems, etc.
Post Reply
juan.delcastillo
Posts: 30
Joined: 02 Feb 2021 19:11

Script player isn't playing anything

Post by juan.delcastillo »

I'm using a DirectorScript to declare a script player variable so the interactive objects of my scene play a certain script when they are clicked, through a C# script called ObjectInteraction. After a while, none of the interactive objects worked because ObjectInteraction couldn't find any scripts being played on the script player. The Unity service is active on script but no Nani scripts are being played

This is DirectorScript:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Naninovel;
using System;
public class DirectorScript : MonoBehaviour
{
    public IScriptPlayer scriptPlayer = Engine.GetService<IScriptPlayer>();
}
void Update() {
Debug.Log(scriptPlayer.PlayedScript.Name);
}

This one is ObjectInteraction:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Naninovel;
public class ObjectInteraction : MonoBehaviour
{
    public string scriptName;
    DirectorScript directorScript;
    public Texture2D magnifierTexture;
    void Start()
    {
        directorScript = FindObjectOfType<DirectorScript>();
    }
    public void OnMouseDown()
    {
        directorScript.scriptPlayer.PreloadAndPlayAsync(scriptName);
    }
    void OnMouseEnter()
    {
        Cursor.SetCursor(magnifierTexture, Vector2.zero, CursorMode.Auto);
    }
    void OnMouseExit()
    {
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }
}

I attach this script to every interactive object and put the name of the script each one has to play

I've tried constantly initializing scriptPlayer but, as expected, the problem is that no Nani scripts are played. I've also checked Script Resources and all scripts are there, they are named correctly and there are no void resources

juan.delcastillo
Posts: 30
Joined: 02 Feb 2021 19:11

Re: Script player isn't playing anything

Post by juan.delcastillo »

Ok, it seems it works if I start the game from the title screen. If I start it on any other scene it won't work. Is this about engine initialization?

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

Re: Script player isn't playing anything

Post by Elringus »

Check integration example project for an example on how to implement interaction dialogues.

Post Reply