I have multiple logos for multiple team all on one texture with a set offset for each.
i want to use the index value of an enum to affect the offset of my material.
enum teams {Team01=0, Team02=1, Team03=2, Team04=3, Team05=4}
var team = teams.Team01;
function Update () {
renderer.material.SetTextureOffset("_MainTex", Vector2(.2 * team, 0));
}
Ive tried to look up enum stuff with javascript but it appears that unity has a custom implementation for enums. I assume i need to cast to int or lookup the index on the “teams”, but not sure how.
Any help would be great.
renderer.material.SetTextureOffset("_MainTex", Vector2(.2 * parseInt(team), 0.0));
Also, enums are implicitly converted to ints if you do stuff like:
var thisTeam : int;
thisTeam = teams.Team01;
var i = 2;
if (i < teams.Team04) //etc.
In this particular case, though, wouldn’t using an array make more sense than enums?
–Eric
Yeap this seem to work… the example i gave above is just a simplified version of what i have in my code. if i were just doing what i have above i would have through about going with the array instead.
Now i cant seem to get the offset to update in real time… i can see the offset changing in my inspector when when the teams are switched… but the texture it self on the mesh doesnt update to reflex this. oh well. ill keep playing around with it and see if i cant get it to work