How do I make Vector2 X and Y values into a float? C#

How do I make Vector2 X and Y values into a variable in C#?

I have looked on the web including the scripting reference for about 2 hours (I’m new) and have found nothing.

I just want to figure out how to extract the X and Y values from a vector 2 and make them into a variable. I would be very grateful if you answered my question with a block of code in C#.

I don’t know how to get the X value from a vector3 either, but I’m assuming they are almost identical for these purposes.

Robertbu’s comment is correct. This will work:

using UnityEngine;

public class Move : MonoBehaviour {
	Vector2 mouse2;

	void Update() {
		mouse2 = Input.mousePosition;
		float mouseX = mouse2.x;
		float mouseY = mouse2.y;

		print("Mouse X is: " + mouseX + " Mouse Y is: " + mouseY);
	}
}

If that doesn’t work, then something is wrong somewhere else. You could tell us what error you’re getting.

Got it!

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour {
	
	public Vector2 mouse2;
	public float x;
	
	void Update() 

	{
		mouse2 = Input.mousePosition;
		x = mouse2.x;
		
	}
	
}

As you can see, I first had to make a new public float next to my new vector2, and then under the void update I made the floats value = the value of X in mouse2.
Thanks for that last post.