TOP VIEW little problem C#

Hi I want to make object look at the mouse
this is kinda 2D game with top view on object, so I want object to turn around y axis ONLY and look atmouse position
This is the code I did, object looks at mouse position, but It is rotating around x and z axis so that spoils it’s movement

	void Update () 
	{
		RaycastHit mousehit;
		Ray ray = camera.ScreenPointToRay (Input.mousePosition);
		if (Physics.Raycast (ray, out mousehit))
			{
			target = mousehit.point;
			target.y =  transform.position.y;
			bject.transform.LookAt(target);
			[COLOR="red"]bject.transform.Rotate.z(0);
			bject.transform.Rotate.x(0);[/COLOR]
			}
	}

this colored in red is something that I’ve tried to write as a fix but it doesn’t work like this.

it looks like this:

as you can see the cube isn’t rotating ONLY around y axis ( :confused: you can’t see mousePosition on screen shoot but I hope you know what is the prob.)

All you are doing is rotating the object 0.

What you want is to set the rotation to 0.

Try: bject.transform.eulerAngles.z = 0;
bject.transform.eulerAngles.x = 0;

Here’s the way I have my top down character look at the mouse position.

using UnityEngine;

public class LookAtMouse : MonoBehaviour
{   
    RaycastHit hit;
    private Vector3 target;
   
    private float RayDistance = 10000.0f;
   
   void Update ()
   {           
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);            
      
        if (Physics.Raycast (ray, out hit, RayDistance))
        {                    
            transform.LookAt(hit.point);
            transform.rotation = new Quaternion(0.0f, transform.rotation.y, 0.0f, transform.rotation.w);

            target = hit.point;
        }            
    }

   public Vector3 GetTarget()
   {
       return target;
   }
}

bject.transform.eulerAngles.x = 0;

is read only, it’s not function for changing value.
(all it does is returns your x or z angle)

and novashot I tryed to remake my code and mix it with yours but it doesn’t works,
then I made new script, copied your code and pasted it and I attached that script on my player object but it doesn’t work
I’m sorry but I’m not too good with C.
can you tell me which part should I change or explain me your code, my camera is not attached on players object, and it’s distance with ground is y = 75

my 1st code worked fine but I wanted rotation around y axis ONLY
my object was rotating around all axis