I want to make a function for movement, that depending on what button is pressed (WASD) that sends passes information to a movement function that then decides which direction the player should move. So if the player presses ‘W’, then I want to pass along that the transform.position.y value is being affected, whereas if ‘D’ is pressed, the x value is affected, I’m trying to typecast an Object to hold the information, but I feel like I’m missing something simple.
private void Update()
{
if (Input.GetKey(KeyCode.W)){
object directionAffected = transform.position.x;
targetPos = new Vector3(transform.position.x, transform.position.y + 1, transform.position.z);
StartCoroutine(Movement(targetPos, directionAffected));
print(targetPos);
}
}
IEnumerator Movement (Vector3 moveTo, object directionAffect)
{
print(directionAffect);
Vector2 theDir;
theDir = (Vector2)directionAffect;
while (Vector2.Distance((theDir.x - moveTo.x)) > 1)
transform.position = Vector3.Lerp(transform.position, moveTo, smoothing * Time.deltaTime);
yield return null;
}
}