I am making an inventory system. So i made an inheritence script calles Items, and i have object that inherit from that. I made different scripts; cubes, spheres and capsules. I have a raycast on click, and then i tell my raycast to look for the item hit. I made a function in the Item base script and then override it in the child scripts. But it always sees it as a cube no matter what i do. I have a cube with the script cubes on it and a capsule with Capsules.
This is my item script;
public virtual GameObject IHaveItem(GameObject currentItem)
{
print("base class enter");
return currentItem;
}
and this is my child inheritence:
public GameObject cubeTex;
public override GameObject IHaveItem(GameObject currentItem)
{
print("cube override");
currentItem = cubeTex;
return currentItem;
}
i do the same for the other two (spheres and capsules)
This is where i look which item i am clicking on:
public void WhichItem()
{
if (Physics.Raycast(transform.position, transform.forward, out hit, 50.0f))
{
Debug.DrawRay(transform.position, transform.forward, Color.red, 50.0f);
if (hit.collider.GetComponent<Items>())
{
print("hit an object");
items.IHaveItem(currentItem);
print("current item 1 =" + currentItem);
currentItem = items.IHaveItem(currentItem);
print("current item 2 =" + currentItem);
LookForSpace();
hitItemSC = true;
}
}
}
Can someone please help me? i tried a lot of stuff and i really cant figure this one out.
If you dont know but have an idea thats good to, im willing to try them.
i just dont wanna lose my inheritence part