Help with classes and object constructors
Hello, i'm trying to create an object with the attributes "type", "multiplier" & "duration". my class is below.
class buff {
var type : String;
var multiplier : int;
var duration : float;
function buff(buffType : String, buffMultiplier : int, buffDuration : float){
type = buffType;
multiplier = buffMultiplier;
duration = buffDuration;
}
}
I want to be able to create a new buff with the aforementioned parameters but i can't seem to correctly call the constructor.
buff curBuff = new buff(buffType, buffMultiplier, buffDuration);
Common error messages are:
"duration/multiplier/type are not members of Object"
"cannot find visible constructor with the parameters (String, int, float)"
"buff is not set to instance"
& "insert semicolon at the end" onto the constructor line (which already has a semi colon)
i've spent hours scouring the internet for help with class constructors to no avail. i'm disappointed unity does not support standard javascript object construction syntax.
Answer by Flokky_ · Sep 19, 2017 at 06:31 AM
Firstly, in Unity there is no JavaScript, the language is UnityScript. And it has some differences.
Secondly, soon Unity will stop using UnityScript at all. So, try to find another way to solve your problem with UnityScript, or just go coding with C#.
See this post with information about what I've said
Damn... lucky me i'm in the 0.8% of people that're using only unityscript :( Thanks for the heads up, but unfortunately this didn't answer my question.
Your answer
![](https://koobas.hobune.stream/wayback/20220612135139im_/https://answers.unity.com/themes/thub/images/avi.jpg)