No problem with interactSphere script... in Unity Turn based Strategy

Hello :slight_smile:
I know it can be strange to create a topic because I have no error but…
When I add after monobehavior the IInteractable in the InteractSphere script, VisualStudio code doesn’t detect any problem even if I haven’t an Interact Function in my script.
Lol for a once I have problem it’s a problem :slight_smile: :sweat_smile:

My sphereIntaractable script:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class InteractableSphere : MonoBehaviour,IInteractable

{

    [SerializeField] private Material greenMaterial;

    [SerializeField] private Material redMaterial;

    [SerializeField] private MeshRenderer meshRenderer;

    private bool IsGreen;

    private void SetGreenColor()

    {

        IsGreen=true;

        meshRenderer.material = greenMaterial;

    }

    private void SetRedColor()

    {

        IsGreen=false;

        meshRenderer.material = redMaterial;

    }

    // Start is called before the first frame update

    void Start()

    {

        SetRedColor();

    }

}

and my IInteractable script:

using System;

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public interface IInteractable

{

    void Interact (Action onInteractionComplete)

    {

    }

}

Good Luck :wink:
François

You have used one of C#'s new features; default interface methods. Your interface have code (even if it’s empty) so you have specified a default. Now you don’t have to have that method when implementing the interface because the compiler will get the default from the interface and use that. So, it’s not an error. If you want it to force you to implement the method, don’t give the interface method any code.

public interface IInteractable
{
    void Interact(Action onInteractionComplete);
}

Ha ok, thanks :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms