GameObject Array | Change Weapon script not working

Hello, I am very new to coding, very new to unity too, I have just been learning and learning coding the last week. Made a basic game where I can run around and have a basic health bar. Now I am pretty good at modeling so I did make 2 weapon models that I added to my hierarchy, I both gave them the tag “Weapon”. Now remember I am completely new at coding so its probably gonna look stupid but atleast I tried eh ^^ I see people around that just ask for a script without even trying.

    public var weapons : GameObject[]; **//create array of gameobjects**
    private var currentw : int; **// var for the currentweapon**
    private var nmrweapons : int; **// var for the total amount of numbers in the array, in this case just 2**
    private var weaponslot = transform.Find("malemodel/forearm.R.001/hand.R/Empty_weapon"); **// var weaponslot created for the bone called Empty_weapon which is a shield of the right hand**
    function Start () {
    weapons = GameObject.FindGameObjectsWithTag("Weapon"); **// put both my weapon models in the gameobject array**
    currentw = 0; **// set the default weapon when game starts to the first weapon thats in the array**
    nmrweapons = weapons.Length; **// set the array length to the var nmrweapons**
    function Update () {
    if(Input.GetAxis("Mouse ScrollWheel")<0) { **// I read somewhere that Input.Axis("Mouse ScrollWheel")<0 is the way to scroll** 
    	if(currentw == nmrweapons){ **// if the current selected weapon is number 1, then set the currentw to number 0, so u can't go past the max array length**
    	currentw = 0;
    	currentw = 1; **// well if it is 0 already then just set it to 1**
    	Changeweapon(currentw); **// run the ChangeWeapon function**
    function Changeweapon(int currentw){ **// run Changeweapon and take the value of currentw with you ( I probably did this wrong, but I have no clue how to do it)**
    currentw = cw; **// here I used the weapons array and the cw(current weapon) to tell which weapon is being set as child of weaponslot (Empty_weapon bone)**
    weapons[cw].parent = weaponslot;
    weapons[cw].localPosition =;
    weapons[cw].localRotation = Quaternion.identity;
    weapons[cw].localScale =;

So I don’t even know if its possible what I am doing, but basicly I am trying to get the currentw number to be the number of the weapon in the gameobject array and make the selected weapon which is currentw the child of a bone that I called “Empty_weapon”.

I get the following compile error: Unexpected token: currentw.

I don’t know if its obvious or not but this is JAVA well thats what I was aiming for anyway ^^

Unity doesn’t do Java. Its not even JavaScript. Its ‘UnityScript’.

I think you meant to write

function Changeweapon(cw:int){

I figure this as currentw is defined in the class and in the function arguments while cw is undefined.

Note that localPosition, rotation, scale and parent are members of Transform not GameObject.


weapons[cw].transform.parent  //etc