WulcN
WulcN

Reputation: 17

How do i change player position in unity?

So im new to c# and i don't know much but i wanna know how to change the position of players and all i have is this line of code: transform.position = 0.067, 1.52, -0.37; It throws an error at me.

Upvotes: 0

Views: 22710

Answers (2)

Ahmed Ali
Ahmed Ali

Reputation: 1966

Transform.position also takes vector3 object new vector3(x,y,z)
Now, you can set all cordinates value in vector3 object & pass it to transform.position.

transform.position = new Vector3(0.067f,1.52f,-0.37f);

Edit:
As you have error about (converting int to float). So wherever you have to write float in unity add keyword f (single small f) after the value.

int a = 4        //int doesn't require `f`
float a = 4.002f //decimal require f, else throw error

Upvotes: 6

Arslan Mughal
Arslan Mughal

Reputation: 35

Try re-positioning using an external reference.

public Transform Target;

void Start()
{
transform.postition = target.position;
}

Just create a gameobject where you want your object to be repositioned and pass that gameobject to your script and press play > it will reposition you object to your target position.

Upvotes: -3

Related Questions