Public override void

1r Program:

using UnityEngine;
public class PickUpObjects : MonoBehaviour
{
public GameObject ObjectToPickUp;
public GameObject PickedObject;

private void Update()
{
if (ObjectToPickUp != null && ObjectToPickUp.GetComponentInParent().isPickable == true && PickedObject == null)
{
if (Input.GetKeyDown(KeyCode.E))
{
PickedObject = ObjectToPickUp;
PickedObject.GetComponent().isPickable = false;
Interact();
}
}

}

public virtual void Interact()
{
Debug.Log(“j”);
}
}

2n Program:

using UnityEngine;

public class PickableObject : PickUpObjects
{
public Item item;
public bool isPickable = true;

public override void Interact()
{
Debug.Log(“s”);
base.Interact();
}

private void OnTriggerEnter(Collider other)
{
if (other.tag == “PlayerInteractionZone”)
{
other.GetComponentInParent().ObjectToPickUp = this.gameObject;
}
}

private void OnTriggerExit(Collider other)
{
if (other.tag == “PlayerInteractionZone”)
{
other.GetComponentInParent().ObjectToPickUp = null;
}

}
}

The public override void doesn’t works. The letter “J” in the first program comes out on the console of Unity, but the letter “S” not.
Anyone can tell me why? Thanks.

Please use the code tags for code.

I have run your code and it works fine. Are you sure you attached the correct script to the object?

2 Likes

Thanks for the help, i will write all the code another time.
And yes, this code is in the right object.