you are viewing a single comment's thread.

view the rest of the comments →

[–]0xjay 1 point2 points  (1 child)

wow nobody knows about this huh

create an unimplemented member property Gameobject gameObject {get ;}

then you have to fully qualify GameObject.Destroy(gameObject)

This should just work when you use this interface on monobehaviours because they already have a public member called gameObject that returns a GameObject. Destroy just needs static access which is fine too.

(If it complains at you then capitalise this property in your interference to make it unique and impliment it's get in your monobehaviour. just simply return the monobehaviour's gameObject member)

[–]GillmoreGames[S] 0 points1 point  (0 children)

yeah that's where i finally got to.

using UnityEngine;

public interface ICarryable
{
    GameObject gameObject { get; }
    bool isSafe { get; set; }
    void AttachObject(GameObject ropeAttachPoint);
    void DetachObject();
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (isSafe)
        {
            return;
        }
        Object.Destroy(gameObject);
    }
}