Enumerator problem

I’ve got a JS Script

enum Attachments {Ironsight  = 0, Acog = 1, Scope = 2}
var currentAttachment = Attachments.Ironsight;

and i want to change the currentAttachment from another JS like:

transform.GetComponent(WeaponScript).currentAttachment = transform.GetComponent(WeaponScript).Attachments.Ironsight;

1 Answer

1

I don’t see a question in there, or any posting of what specific error you’re seeing, so I’m going to guess: it doesn’t like the way you’re defining transform.GetComponent(WeaponScript).Attachments.Ironsight;

In this case, you want to use the name Attachments, rather than a specific instance of attachments. So what you want is something like:

... = WeaponScript.Attachments.Ironsight;

No, Attachments' is not a member of 'WeaponScript'.

Okay, if it's contained within a class you'll need ClassName.Attachments.Ironsight; otherwise, you'll want Attachments.Ironsight; In either case, what you want is essentially the 'path' to that variable. So if it's in a namespace, you want the namespace first.

The enum and the Attachments are in the variable field var x : float; var asd : Transform; enum Attachments{Ironsight = 0, Other = 1} currentAttachment = Attachments.Ironsight; function Start() { }