am getting this error in my script - `EnemyAI.CheckGround(UnityEngine.Vector3)': not all code paths return a value

here is my script the error is on line 78 Vector3 CheckGround (Vector3 pos) {
I have tried several ways to correct this but still coming up with the same issue - how do I go about writing this code so I can fix this error or what do I need to change in the script so this can work properly - I tried using a debugger but of course it wouldn’t tell me a solution on how to fix the issue. - if anyone can help me I would appreciate it

thanks in advance

public class EnemyAI : MonoBehaviour {

public float gravity;
public Vector2 velocity;
public bool isWalkingLeft = true;

LayerMask floorMask;

private bool grounded = false;

private enum EnemyState {

	walking,
	falling,
	dead
}

private EnemyState state = EnemyState.falling;

// Use this for initialization
void Start () {

	enabled = false;

	fall ();

}

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

	UpdatedEnemyPosition ();

}

void UpdatedEnemyPosition () {

	if (state != EnemyState.dead) {

		Vector3 pos = transform.localPosition;
		Vector3 scale = transform.localScale;

		if (state == EnemyState.falling) {

			pos.y += velocity.y * Time.deltaTime;

			velocity.y -= gravity * Time.deltaTime;
		}

		if (state == EnemyState.walking) {

			if (isWalkingLeft) {

				pos.x -= velocity.x * Time.deltaTime;

				scale.x = -1;

			} else {

				pos.x += velocity.x * Time.deltaTime;
				
				scale.x = 1;

			}
		}

		if (velocity.y <= 0)
			pos = CheckGround (pos);

		transform.localPosition = pos;
		transform.localScale = scale;
	}
}

 Vector3 CheckGround (Vector3 pos) {

	Vector2 originLeft = new Vector2 (pos.x - 0.5f + 0.2f, pos.y - .05f);
	Vector2 originMiddle = new Vector2 (pos.x, pos.y - .5f);
	Vector2 originRight = new Vector2 (pos.x + 0.5f + 0.2f, pos.y - .05f);

	RaycastHit2D groundLeft = Physics2D.Raycast (originLeft, Vector2.down, velocity.y * Time.deltaTime, floorMask);
	RaycastHit2D groundMiddle = Physics2D.Raycast (originMiddle, Vector2.down, velocity.y * Time.deltaTime, floorMask);
	RaycastHit2D groundRight = Physics2D.Raycast (originRight, Vector2.down, velocity.y * Time.deltaTime, floorMask);

	if (groundLeft.collider != null || groundMiddle.collider != null || groundRight.collider != null) { 

		RaycastHit2D hitRay = groundLeft;
		
		if (groundLeft) {
			hitRay = groundLeft;
		} else if (groundMiddle) {
			hitRay = groundMiddle;
		} else if (groundRight) {
			hitRay = groundRight;

		}

		pos.y = hitRay.collider.bounds.center.y + hitRay.collider.bounds.size.y / 2 + .5f;

		grounded = true;
		
		velocity.y = 0;

		state = EnemyState.walking;

	} else {
		
		if (state != EnemyState.falling) {
			
			fall ();
		}
	}
}

	void OnBecameVisible () {

	enabled = true;
}

void fall () {

	velocity.y = 0;

	state = EnemyState.falling;

	grounded = false;
}

}

Your function Vector3 CheckGround (Vector3 pos) is meant to return a Vector3, but you never return anything - that’s the error.

I noticed that you changed the Y value of the parameter “pos” - are you trying to ‘save’ the return value straight into that parameter? Because if so the function should then be a void return and you need to use the out keyword on that parameter like so: void CheckGround (out Vector3 pos)

I was able to fix my error - I just had a line a code in the wrong place - I appreciate you replying and helping me out - thanks again

happy holidays @dhore

hi where was your error i am copying the same script and i did not find the error