Weird script behaviour

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

Weird script behaviour

Post by juan.delcastillo »

Hello. I created a custom command for my project and, since then, my object interaction doesn't work at all

This the custom command script

Code: Select all

using Naninovel;
using Naninovel.Commands;
using UniRx.Async;
using UnityEngine;
[CommandAlias("fadeOut")]
public class FadeOutCommand : Command
{
    Animator screenAnimator;
    public override UniTask ExecuteAsync(CancellationToken cancellationToken = default)
    {
        screenAnimator = GameObject.Find("BlackScreen").GetComponent<Animator>();
        screenAnimator.Play("FadeOut");
        return UniTask.CompletedTask;
    }
}

This is the object interaction code

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectInteraction : MonoBehaviour
{
    public string scriptName;
    public Texture2D magnifierTexture;
    [HideInInspector] public GameObject pressedObject;
    CameraMovement cameraScript;
    delegate void ClickedAction();
    event ClickedAction clickEvents;
    void Start()
    {
        cameraScript = GameObject.Find("Main Camera").GetComponent<CameraMovement>();
        clickEvents += DirectorScript.directorSingleton.DisableObjectInteraction;
        clickEvents += cameraScript.SetDirection;
    }
    public void OnMouseDown()
    {
        cameraScript.pressedObject = gameObject;
        DirectorScript.directorSingleton.scriptName = scriptName;
        clickEvents();
    }
    void OnMouseEnter()
    {
        Cursor.SetCursor(magnifierTexture, Vector2.zero, CursorMode.Auto);
    }
    void OnMouseExit()
    {
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }
}

Ever since I created the custom command, this script does nothing, even though this script is enabled in all interactive objects. I've also deleted every @fadeOut line and it won't work either

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

Re: Weird script behaviour

Post by juan.delcastillo »

juan.delcastillo wrote: 29 Apr 2021 17:28

Hello. I created a custom command for my project and, since then, my object interaction doesn't work at all

This the custom command script

Code: Select all

using Naninovel;
using Naninovel.Commands;
using UniRx.Async;
using UnityEngine;
[CommandAlias("fadeOut")]
public class FadeOutCommand : Command
{
    Animator screenAnimator;
    public override UniTask ExecuteAsync(CancellationToken cancellationToken = default)
    {
        screenAnimator = GameObject.Find("BlackScreen").GetComponent<Animator>();
        screenAnimator.Play("FadeOut");
        return UniTask.CompletedTask;
    }
}

This is the object interaction code

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectInteraction : MonoBehaviour
{
    public string scriptName;
    public Texture2D magnifierTexture;
    [HideInInspector] public GameObject pressedObject;
    CameraMovement cameraScript;
    delegate void ClickedAction();
    event ClickedAction clickEvents;
    void Start()
    {
        cameraScript = GameObject.Find("Main Camera").GetComponent<CameraMovement>();
        clickEvents += DirectorScript.directorSingleton.DisableObjectInteraction;
        clickEvents += cameraScript.SetDirection;
    }
    public void OnMouseDown()
    {
        cameraScript.pressedObject = gameObject;
        DirectorScript.directorSingleton.scriptName = scriptName;
        clickEvents();
    }
    void OnMouseEnter()
    {
        Cursor.SetCursor(magnifierTexture, Vector2.zero, CursorMode.Auto);
    }
    void OnMouseExit()
    {
        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
    }
}

Ever since I created the custom command, this script does nothing, even though this script is enabled in all interactive objects. I've also deleted every @fadeOut line and it won't work either

EDIT: I used a backup this time and ObjectInteraction stops working the moment I put @fadeOut in any Nani script. Enabling or disabling ObjectInteraction doesn't work either, both in editor mode and play mode. I checked the assembly information of FadeOutCommand and it refers to Assembly-CSharp.dll, don't know if this means something

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

Re: Weird script behaviour

Post by Elringus »

Assembly-CSharp is where your custom scripts code is compiled by default (if you're not using asmdefs). The issue is more about general Unity/C# stuff rather than Naninovel.

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

Re: Weird script behaviour

Post by juan.delcastillo »

Any place where I can start looking for info about it? I mean something more specific

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

Re: Weird script behaviour

Post by Elringus »

The first step is to isolate what exactly is not behaving as expected; then, in case it's Naninovel-related, feel free to ask here; otherwise, use Unity forum or other related resources.

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

Re: Weird script behaviour

Post by juan.delcastillo »

I've solved it. It was a problem of OnMouse event and colliders I forgot that existed

Post Reply