Script player isn't playing anything

Posted: 19 Feb 2021 09:55
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


Re: Script player isn't playing anything

Posted: 19 Feb 2021 10:01
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?


Re: Script player isn't playing anything

Posted: 19 Feb 2021 11:40
by Elringus

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