Changing "right" in Vector3.right to a variable

Im trying to change the “right” in transform.position += Vector3.right * speed * Time.deltaTime;
to my variable: direction.
My variable: private string direction = “right”;

So when i change it, it looks like this: transform.position += Vector3.direction * speed * Time.deltaTime;

Because then i can change the direction string to either right,left, up or down.

But of course it doesn’t work, so how do i implement my variable direction to the vector3, like i did above?

I don’t understand why you try to do this way while having a private Vector3 direction would be muuuch simpler…

Anyway… Try the following code which involves reflection

// At the top of your script
using System.Reflection;

// ....

PropertyInfo propertyInfo = typeof(Vector3).GetProperty(direction, BindingFlags.Public | BindingFlags.Static); 

// Use the PropertyInfo to retrieve the value from the type by not passing in an instance
Vector3 vector = (Vector3) propertyInfo.GetValue(null, null);

transform.position += vector * speed * Time.deltaTime;