Horje
2d look at unity Code Example
2d look at unity
//this code will point the object to the mouse
Vector3 diff = Camera.main.ScreenToWorldPoint(Input.mousePosition) 
	- transform.position;
diff.Normalize();
 
float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90);
unity 2d looka tt mouse
void Update() {
     Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
     float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
     transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
unity look at 2d
Vector3 dir = target.position - transform.position;
 float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
2d look at unity
//Look at 2D job using the unity jobs system
struct LookAtJob : IJobParallelForTransform
{
    public NativeArray<Vector2> targetPositions;
    public void Execute(int index, TransformAccess transform)
    {
        Vector2 dir = targetPositions[index] - (Vector2)transform.position;
        float angle = math.degrees(math.atan2(dir.y, dir.x));
        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
}




Csharp

Related
NewtonSoft get base64 string Code Example NewtonSoft get base64 string Code Example
multi case in c# Code Example multi case in c# Code Example
declare string array c# without size Code Example declare string array c# without size Code Example
remove control characters from string c# Code Example remove control characters from string c# Code Example
remove multiple items from list c# Code Example remove multiple items from list c# Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8