Quantcast
Channel: Add onto method in parent class from inherited class - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Add onto method in parent class from inherited class

$
0
0

Suppose that you have a function in the parent class, it does x and y. But now in the inherited class, you want to make the function also do z. You can't overwrite it because that would mean that the function no longer does x and y.

Here is my unity example:

This is the code in the parent class:

protected virtual void Start () {    MyRigidBody = gameObject.GetComponent<Rigidbody>();    if(Controls.Length < 4)        throw new System.Exception("Controls not assigned correctly");}

Now I want to do something like this:

protected void Start () {    MyBase.Start();//MyBase.Start doesn't work    BlahBlahBlah();    Stuff();}

How would I go about doing this?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>