How I make fixed localScale

I want to make equalize X to transform’s localScale.x in C#

I have code like that,

but I get error CS0029: Cannot implicitly convert type UnityEngine.Vector3' to float’

float X;
Transform target;
   
void Start(){
	
	X = target.transform.localScale = new Vector3(X, 0, 0);   		
	

}

Lets look at your code.

In the case of assignment, it is resolved right to left.

First you have

new Vector3(X, 0, 0);

This creates an object of type Vector3. Next you have:

target.transform.localScale = new Vector3(X, 0, 0);

This assigns that Vector3 to localScale which is a variable of type Vector3 so, so far, so good.

Last you have:

X = target.transform.localScale = new Vector3(X, 0, 0);         

The value of an assignment operation is the value that was assigned, so this part…

 target.transform.localScale = new Vector3(X, 0, 0);       

returns the Vector3 yo uasigned to localScale.

But X is not a Vector3 field, its a float.

And thats why its an error. You are trying to assign an object to the wrong type of variable to contain it.

Instead, split it into two lines like this:

target.transform.localScale = new Vector3(X, 0, 0);       
X = target.transform.localScale.x;

Note however that the second line is meaningless since target.transform.localScale.x was JUST set to X in the line above.