Custom Transform Name? Beginner question!

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

It looks like you are trying to recreate transform.Translate.

This would be a way of doing it

Vector3 position = transform.position;
position.y += speed;
transform.position = position;

Thanks for the quick response guys.

@DanielQuick
Probably, I wouldn’t know yet. I am still at a very elementary stage. I did go through that, nevertheless.

@HelloMeow - yeah that is something I was looking for. I am going to try it right away.