Inheritance and Update Method
Hi guys ! Big question over here. So basically i understand inheritance and OOP stuff in general but when it comes further more qquestions arise ;)
I have Class A and this class implements some methods:
Class A:
public void Update
{
TowerStateCheck()
}
public void TowerStateCheck()
{
if (sth == sth)
{
CheckForEnemies();
SetLerpRotationForEnemy();
ShotEnemy();
}
else if (sthElse == sthElse)
{
//Do STH
}
}
Then is it possible to override SetLerpRotation and ShotEnemy in child class so they do different stuff , and methods SetLerpRotation , ShotEnemy will not be called in Class A (parent class).
If you dont uderstand what i meant to tell you i can explain it clearer. Any answers will be appreciated !!!!
Answer by Hellium · Sep 06, 2019 at 01:25 PM
Class A:
protected virtual void Update
{
TowerStateCheck()
}
public virtual void TowerStateCheck()
{
if (sth == sth)
{
CheckForEnemies();
SetLerpRotationForEnemy();
ShotEnemy();
}
else if (sthElse == sthElse)
{
//Do STH
}
}
public virtual void SetLerpRotationForEnemy()
{
Debug.Log("SetLerpRotationForEnemy in class A");
}
public virtual void ShotEnemy()
{
Debug.Log("ShotEnemyin class A");
}
Class B:
protected override void Update
{
base.Update();
}
public override void TowerStateCheck()
{
if (sth == sth)
{
CheckForEnemies();
}
else if (sthElse == sthElse)
{
//Do STH
}
}
public override void SetLerpRotationForEnemy()
{
Debug.Log("SetLerpRotationForEnemy in class B");
}
public override void ShotEnemy()
{
Debug.Log("ShotEnemyin class B");
}
Great thanks ! Example just like i needed. Need to check few more examples before i hop on the project ;)
Your answer
Follow this Question
Related Questions
Randomizing and using Bool values 0 Answers
Class structure for diferent item types and items that do different things. 0 Answers
How to make drop down list of classes in an array of classes (in the inspector) 0 Answers
Array of unique inherited classes? 0 Answers
Custom class, Null Reference Exception 4 Answers