set layer weight

hello ladies and gentlemen, I have a problem with one scriptit; is about LAYER WEIGHT, I want switch from base layer to another layer, (in animator controller), if I am pressing a button or key. I tried to figure it out, but I don’t understand, what is wrong. I have a script it is here. Thank for help and I am grateful in advance.

using UnityEngine;
using System.Collections;

public class newWeightControll : MonoBehaviour {

private Animator anim ;


// Use this for initialization
void Start () {

	
}

// Update is called once per frame
void Update () {

	
	if(Input.GetKeyDown ("3")){                     // this we need to controll our layer weight system
		anim.SetLayerWeight (2, 1f);
		anim.SetInteger("CorrentAction", 3);
	} 
	if(Input.GetKeyUp("3")){
		anim.SetInteger("CorrentAction", 0);
	}
}

}

I’m not sure if you still need it, but I’m going to answer anyway, in case anyone goes through this post.
Firstly, I’m not sure that your Input.GetKeyDown("3") works like that, I would use Input.GetKeyDown(KeyCode.Alpha3).

OK, so, layer index changes constantly, from what I know. If you insert a Debug.Log(anim.GetLayerIndex("name of your layer")) on line 12 you will see that it prints some different numbers, even though you want the speciffic layer.

What I used and worked for me is anim.SetLayerWeight (anim.GetLayerIndex ("layerName"), 1)

Hope I helped whoever comes through the post.