Every example I’ve seen of inherited classes, do not explain how the Child class can function as though it were a class of it’s own. And I’m getting errors on things like transform
and position
and I’m not understanding why these aren’t able to be called while that Script is on the GameObject itself. For my situation I had public class Tree : Monobehavior
and had it working just fine. However constantly calling from my handler script:
if (workLoad.name == "Tree1")
{
workLoad.GetComponent<Tree>().attacker = gameObject;
}
if (workLoad.name == "Log")
{
workLoad.GetComponent<Log>().carrier = gameObject;
}
Get’s to be a little numbing and messy. So I tired to setup a RawResources Base class, and a Resources class, to handle the many many objects/items I plan to use. And this one block in particular(Tree class) lit up like a christmas tree with errors:
void WhenDie()
{
log.transform.SetParent(null, false);
log.transform.forward = attacker.transform.forward;
log.transform.position = transform.position;
log.transform.Rotate(Vector3.right * 5);
log.SetActive(true);
Destroy(this.gameObject);
}
It’s constantly saying that transform
doesn’t exist, and after applying private object transform;
as one answer I found showed to put into the Tree class, then position
is saying it doesn’t exist…
I’m sorry if this is a redundant question, but I truly cannot find an answer to why I’m getting these errors, or even why I should attempted using Inherited Classes in the first place. Can anyone help me by explaining why these error’s are happening, and possibly give me a clue to how to make it all work?