Answers for "rotation with mouse unity"

C#
1

rotation facing mouse unity

//Rotate Object to face Mouse (2D, Rotate on Z-Axis)

Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
Vector3 dir = Input.mousePosition - pos;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
Posted by: Guest on January-16-2021
2

how to chagne rotation in unity

transform.eulerAngles = new Vector3(0f, 180f, 0f); // rotates 180 degrees
Posted by: Guest on February-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language