How to rotate an object by its pivot in script

I need to rotate an object by its pivot using the mouse input, but I can’t seem to find a reference in the Unity Script Reference on rotating by pivots in script. Does anyone know how to do it?

As far as I know, I don’t think you can set a pivot point.

(I am still fairly new to unity)

But What I do is make a empty game object and put childs in there… Using the parent as a pivot point and rotate that.

Hope that helps. Good luck!

You can use pivot point in unity, next to the scale tool you see a button ‘center’ . Hit this button and your object will become a pivot point. I used this and it works perfectly

You can use this

private Vector3 object_pos;
	private Vector3 mousePosition;
   
	public float moveSpeed = 0.1f;
	public Transform target; //Assign to the object you want to rotate
	float angle;



	// Use this for initialization
	void Start () {
	}



	void Update () {
		//rotation
		Vector3 mousePos = Input.mousePosition;
		mousePos.z = 5.23f;

		Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
		mousePos.x = mousePos.x - objectPos.x;
		mousePos.y = mousePos.y - objectPos.y;
		float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
		transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));