Hi,
I’m new to unity. I’m having a problem with creating a new object and that object’s variables showing up in the editor. I’ve created a class called Gun and inside of that class I have a constructor of course and a function called “Fire”:
class Gun{
// whatever vars...
function Gun( //constructor vars... ){
//whatever vars = constructor vars…
}
function Fire(){
// Fire's gun
}
Then I declare and create new objects from the Gun class, say…
var ak47 = new Gun( // Gun vars);
So in the editor it’ll show the variables in that new gun:
Ok, everything’s looking good up to this point right?… Now here’s where the problem comes in.
My “Fire” function requires the Component class because it uses Transform, 4, and Instantiate.
So to fix this I extended the Component class to my Gun class:
class Gun extends Component{
Now when I do this it fixes all the errors and makes the function “Fire” run as intended but now when I declare and create a new gun object, lets say the AK-47 again:
var ak47 = new Gun( // Gun vars);
Now all the variables for the newly created gun object are gone and I’m left with this:
I know it has to do with the Gun class inheriting the Component class of course but I have no idea about anything after that.
I’m still really new to unity and moderately new to programming.
Since this is a free service I highly appreciate any and all input and answers.
Thanks,
Kev