[C#] Getter Setter Polymorphism and me

Hi,

would like to code common behaviour for bullets, like timed life.
So i created a superclass and gave it all it needs to know.
Then i made a subclass and tried to bring things to work…
Somehow i try to change here and there but in the end i just gain a lot of errors.

Here is the Code.
SuperClass:

using UnityEngine;
using System.Collections;

public class TimedLifeObject : MonoBehaviour {
	
	private float lifetime_Limit;
	private float lifetime_Timer;
	


	
	// Use this for initialization
	void Start () {
		lifetime_Limit = 1;
		lifetime_Timer = 0;
	}
	
	// Update is called once per frame
	void Update () {
		lifetime_Timer += Time.deltaTime;
		if (lifetime_Timer >= lifetime_Limit)
			Destroy(this);
		
		
	}
	
	public float lifetime_Max {
		get { return lifetime_Limit;}
	    set { lifetime_Limit = value; }
	}
	
 	public float lifetime_Left {
		get { return lifetime_Timer; }
	}	
}

SubClass:

using UnityEngine;
using System.Collections;

public class BulletBehaviour : TimedLifeObject {

	// Use this for initialization
	public void Start () {
		lifetime_Max = 5F;
	}
	
	// Update is called once per frame
	void Update () {
		base.Update();
		transform.Translate(+.1F,0,0, Space.World);
	}
}

I appriciate any help.
greets

you have an update in both the super and the child class.

Both aren’t getting called.

If you want the child class to have it, make the super class implement Update as a public or protected (whichever) virtual method:

superclass:

protected virtual void Update()
{
    //do stuff
}

childclass:

protected override void Update()
{
    base.Update();
    //do more stuff
}

See the way you have it, both Updates are private. You’re able to have two private methods of the same name in different classes that inherit one from the other, because they’re completely encapsulated.

But, when unity comes along to reflect out your Update method, it gets all methods inside your class of the name Update, and it uses the first one it comes across. Which is the one in the child class.

You need to use virtual methods in this case so that the method it grabs chains up to the super class as well.

You blasted me with this high quality awnser.
It helped and solved the problem as well as tought me alot.

I thank you very much!