Hi all,
Just started out on C# on Unity and in general.
While learning and messing around, I was wondering how would you set a custom variable that holds the translate information of a gameObj and you use that to call the transform of that gameOBJ.
So I have this code that moves a particular gameOBJ (named train)
// Update is called once per frame
void Update () {
//Moving the train
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position = new Vector3 (transform.position.x, transform.position.y + speed, transform.position.z);
}
Now what I want to do is, have something like this
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position = new Vector3 (valueX, valueY + speed, valueZ);
}
instead of
{
transform.position = new Vector3 (transform.position.x, transform.position.y + speed, transform.position.z);
}
What I was trying was to create a function which would take in arguments from the the transform.position
Kind of stuck here!
public float customTrans(float valueX, float valueY, float valueZ)
{
Vector3 batPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);
return batPositon;
}
Thank you for the help & regards.
-G