- Home /
Question by
yveris · Jul 14, 2012 at 11:46 PM ·
updateinheritanceoverride
[Solved] Base Update Function? Does It Use Overriden Methods?
If you override a function shoot(params...) inherited from the base class, and the base class uses foo in its update function. When you call base.Update in the subclass' update function; does it use the original shoot or the new override shoot?
Comment
I notice this is a duplicate question - please only post once - sometimes moderation takes a while.
Yeah I thought my post didn't go through so I made another one
Answer by Avaista · Jul 15, 2012 at 12:47 AM
public class Parent:MonoBehaviour
{
public virtual void Update()
{
shoot();
}
public virtual void shoot()
{
Debug.Log("Pew Pew");
}
}
public class Kid:Parent
{
public override void shoot()
{
Debug.Log("Boom HeadShot");
}
public override void Update()
{
base.Update();
}
}
Just wanted to make surethat I got what you were saying correctly. This will use the kids shoot on update.
Just FYI, next time just test it yourself, people tend to ignore posts around here that can be easily tested, better use of your time to just do it youself.
Good Luck. Have Fun.