- Home /
Extended class functions
Lets say i had a simple class that extends another class:
class Item {
private var name : String = "itemName";
private var price : int = 21;
private var weight: int = 1;
function _get(what:String){
if(what=="price")return price;
if(what=="weight")return weight;
}
}
class Weapon extends Item {
private var damage : int = 10;
private var speed : int = 5;
function _get(what:String){
if(what=="damage")return damage;
if(what=="speed")return speed;
}
}
function Start () {
var wep = new Weapon();
print(wep._get("damage"));//prints 10
print(wep._get("price")); //prints 0 ???
}
The problem is - i can't seem to get the base class variables - price or weight in this example. Maybe there is a special way of extending a function?
Any help would be appreciated.
Comment
Never$$anonymous$$d, figured it out... function names must be different - and the first function can call the second one with the same parameter. - result is still the same.
Your answer
![](https://koobas.hobune.stream/wayback/20220613071014im_/https://answers.unity.com/themes/thub/images/avi.jpg)