Rotate GameObject

Hi, sorry for my english.

I have an object/player, this object translate on -z axes.

The object translate and rotate with acceleration thanks to this script:

private Quaternion localRotation; 

void Start () {
        localRotation = transform.rotation;

void Update () {
        gameObject.transform.Translate(new Vector3(0,0,-1));
        localRotation.z = Input.acceleration.x;
        transform.rotation = localRotation; 

How can I do to rotate the object to make it to translate to z+ axes.

I Tried with

player.transform.rotation = Quaternion.Euler(0,0,180);

in OnCollisionEnter but this script doesn’t work. The player doesn’t rotate in z axis.


You should not use force a rotation, rather use the Rotate method.
For example:

 gameObject.transform.Rotate(new Vector3( 0.1f, 0.2f, 0.3f), Space.Self);

I hope I understood well your problem.