unity3d - Why I can't access my script variable from class? -


as topic says. can't access variable class made in same script. it's in same script, , variables(as see) public. ideas? tried googling "how access script variable class" didn't found anything.

code:

public var ludnosc = new array(); var humancount : int;  public class human {     public var id : byte;     public var creaturetype = "human";     public var gender : boolean; // false = k, true = m     //public var firstname : string; <- opcja wprowadzenia później     //public var lastname : string; <- opcja wprowadzenia później     public var age : byte;     public var pregnant : boolean = false;     function breed(partner) {         if(this.age<16) {         debug.log("woman id " + this.id + " young pregnant. must 16 or older.");         }         else {             var success = random.range(0.0, makepregnantchance);             debug.log("breed chance of partners ids [" + this.id + ", " + partner + "] " + success*100 + "%.");             if(success>0.50) {                 this.pregnant = true;                 debug.log("creature of type " + this.creaturetype + ", id " + this.id + " pregnant!");                 ludnosc.push(new human()); //line 44 | tworzymy nowego czlowieczka                 var temphuman = ludnosc[humancount+1] human //line 45                 temphuman.id = humancount+1; //line 46                 temphuman.age = 1;                 var losujplec = random.range(0.0, 1.0);                 temphuman.makepregnantchance = 18/temphuman.age;                 }             }     }     public var parents : byte[]; //najpierw podajemy id matki, potem id ojca.     public var makepregnantchance : float; } 

bugs:

assets/textpierwszy.js(44,33): bce0005: unknown identifier: 'ludnosc'. assets/textpierwszy.js(45,49): bce0005: unknown identifier: 'ludnosc'. assets/textpierwszy.js(45,57): bce0005: unknown identifier: 'humancount'. assets/textpierwszy.js(46,48): bce0005: unknown identifier: 'humancount'. 

your code here:

public var ludnosc = new array(); var humancount : int;  public class human {... 

needs be:

public class human {     public var ludnosc = new array();     var humancount : int; 

that of course, if they're related class, if not, you'll better off creating class hold else humanextras (or similar),for example.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -