Saturday, July 28, 2018

What do "position.transform" and "Input.GetAxis" mean in Unity?


I am making the transition from Game Maker to Unity, but I feel lost when I look at Unity's programming.


When I followed a tutorial to make basic movements, I had this code:


public Vector3 playerPos;
void Update ()
{

float V_X = transform.position.x;
V_X += Input.GetAxis("Horizontal") / 2;
playerPos = new Vector3(V_X, 0, 0);
transform.position = playerPos;
}

A few things are confusing me here:




  • What is transform? And why is position something that is a part of it? Why not have the position of the objects represented by just x rather than transform.position.x?





  • Is GetAxis(...) a command that has a return value? Why is in "sub-categorized" under Input? And why not detect the key presses directly?






No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...