Raycast Animation with tags not working correctly

well i made a similar question but not the same i have a script

#pragma strict

var up = false;

function Update() {
	var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;

	if (Physics.Raycast (ray, hit, 2)) 
	{
		Debug.DrawLine (ray.origin, hit.point, Color.red);
		if(hit.transform.gameObject.CompareTag ("Labyrinth") && up == false)
		{
			animation.Play("UpArmLeft");
			{
				up = true;	
			}
		}
		
		if(!hit.transform.gameObject.CompareTag("Labyrinth") && up == true)
		{
			animation.Play("DownArmLeft");
			{
				up = false;
			}
		}	
	}

Th animation UpArmLeft works perfectly but the other doesnt work so great because i have to play it when the player isn`t at the wall anymore or if he isnt looking at the wall then he should play the animation too but it doesnt work really good because sometimes it works but with delay and other times it doesnt work at all

any advice on how to make the animation play when the player is off the wall or isnt looking at it would be very appreciated

thanks in advance skullbeats1

If I’m understanding this right, when the character is close to a wall he lifts his arm (with the weapon I assume) so it doesn’t go through the wall.
If that is the case, it also looks like this may be First Person.
If these 2 statements are true, then the problem should be the Raycast. You’re casting the ray from the camera to the mouse position. The problem with that is, that while in first person, the mouse isn’t in the center of the screen. It moves around.
instead you should use:

if (Physics.Raycast(MainCamera.transform.position, MainCamera.transform.forward, hit, 2))

This way, the ray is always cast from the Main Camera straight forward.
Also, you can remove the { } above and below the up=true and up=false.