Reputation: 45
I'm trying to use a parent class method in my subclass but it takes always the parent class attributes instead of the subclass attributes..
here the example:
public class Character : MonoBehaviour{
protected val = 5;
public void example(){
Debug.Log(val);
}
}
public class Enemy : Character{
public void Reset(){
val = 10;
}
}
I get always 5 when I do .example() on a Enemy object...
thanks!
Upvotes: 0
Views: 84
Reputation: 14171
Do you ever call Reset
on Enemy
?
If you don't val
will have its default value which is 5
.
Upvotes: 5