error CS0019: Operator `<=' cannot be applied to operands of type `UnityEngine.Vector3' and `float'

Hello, sorry for double posting the same thing but something very bizarre happened when I submitted my question here in this link. I can’t even respond to people’s comment or accept it if it were the most helpful answer, so I hope this is forgivable.

So like I was saying in the first post I was trying to make an enemy do an attack animation when they got close enough to the player, but I have gotten caught into a snag. When using comparison operators to compare Vector3 and float values, its not going to work out is what I found out. I tried looking in the documentation but I feel like I’m going in there blindly and don’t know where to start really to solve this. I would really appreciate any help from people and take advises they would give.

here is my code that I was working on that started causing me trouble:

 using UnityEngine;
    using System.Collections;
    
    public class EnemyAIMelee : MonoBehaviour 
    {
    	public float targetDistance = 20.0f;
    	public float attackDistance = 10.0f;
    
    	public float enemySpeed = -40.0f;
    	public float chaseSpeed = 0.0f;
    
    	private bool spawningIn = true;
    	private bool unlockAI = false;
    	public GameObject playerCharacterManager;
    
    	void Start()
    	{
    		playerCharacterManager = GameObject.FindGameObjectWithTag ("PlayerCharacterManager");
    	}
    
    	// Update is called once per frame
    	void LateUpdate () 
    	{
    		SpawnIn ();
    		MovingAI ();
    		AttackAI ();
    	}
    
    	void SpawnIn()
    	{
    		if (spawningIn == true) 
    		{
    			GameObject plane = GameObject.FindGameObjectWithTag("PlayerPlane");
    			if (transform.position.z - plane.transform.position.z <= targetDistance) 
    			{
    				SendMessage("EnemyMovingAnimation", false);
    				transform.parent = plane.transform;
    				unlockAI=true;
    				spawningIn = false;
    			}
    			
    			else
    			{
    				SendMessage("EnemyMovingAnimation", true);
    				transform.position += transform.forward*enemySpeed*Time.deltaTime;
    			}
    		}
    	}
    
    	void MovingAI()
    	{
    		if(unlockAI == true)
    		{
    			float chasingSpeed = chaseSpeed * Time.deltaTime;
    			transform.position = Vector3.MoveTowards (transform.position, playerCharacterManager.transform.position, chasingSpeed);
    			SendMessage ("EnemyMovingAnimation", true);

//this if statement is giving me the problem
    			if(playerCharacterManager.transform.position <= attackDistance)
    			{
    				AttackAI ();
    			}
    		}
    	}
    
    	void AttackAI()
    	{
    		SendMessage ("EnemyAttackAnimation", true);
    	}
    }

Hi
Problem is you are comparing two different things.
eg : Vector3(0,50,0) cannot be compared to 10.0f
but you can definitely compare 5 >=10 because the values are of same type.

if you want to compare distance in x axis do the below code

 if(playerCharacterManager.transform.position.x <= attackDistance)
                 {
                     AttackAI ();
                 }

Hope I am able to make my point clear.

Just like the answer in your other question says, you can’t compare a vector3 and a float… I mean how would you say which is bigger, point (2,2,1) in space or 8?

You can however compare the distance between 2 points or a lenght of a vector to a float. The length of a vector from (0,0,0) to (2,2,1) is smaller than 8.

You have to use Vector3.magnitude or Vector3.Distance() in your comparison to compare distances