How to change the gun from Position A to B and again B to A ?

I am using Unity 5.6.1
I have model of gun and I want to do that, if I press the Right Shift Key the Gun position get change to
Vector X, Y and Z and as I release the key the Gun again smoothly comes to its initial position! Is there anyone who have solution for my problem. Its urgent ! :slight_smile:
Thanks in advance !
** Sorry for Messy English ! **

You could try to modify the gun position over time.

public float lerpSpeed = 1.5f;
public Transform gun;
public Vector3 onKeyPos;

Vector3 origPos;

void Start() {
    if (gun == null) {
        Debug.LogWarning('Gun transform is null, the component has been disabled.');
        enabled = false;
        return;
    }
    origPos = gun.transform.position;
}

void Update() {
    if (Input.GetKey(KeyCode.RightShift)) { //Move the gun towards the onKeyPos
        gun.position = Vector3.Lerp(gun.position, onKeyPos, Time.deltaTime * lerpSpeed);
    }
    else {
        gun.position = Vector3.Lerp(gun.position, origPos, Time.deltaTime * lerpSpeed);
    }
}

You could try to modify the gun position over time.

public float lerpSpeed = 1.5f;
public Transform gun;
public Vector3 onKeyPos;

Vector3 origPos;

void Start() {
    if (gun == null) {
        Debug.LogWarning('Gun transform is null, the component has been disabled.');
        enabled = false;
        return;
    }
    origPos = gun.transform.position;
}

void Update() {
    if (Input.GetKey(KeyCode.RightShift)) { //Move the gun towards the onKeyPos
        gun.position = Vector3.Lerp(gun.position, onKeyPos, Time.deltaTime * lerpSpeed);
    }
    else {
        gun.position = Vector3.Lerp(gun.position, origPos, Time.deltaTime * lerpSpeed);
    }
}

Sorry, It didnot work for me I put the value of origPos and OnKeyPos and add gun to Gun`s transform after that when play game and press shift key the gun goes far away from camera and as I release key it comes just behind the camera ! :confused: Is there any solution for problem ! :slight_smile: And Yes I add these script in WeaponHolder which is empty Gameobject and contains one more script of sway !