Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity sprite disappears when using transform.lookat

// Do not use "transform.LookAt" for 2D 
// Instand use something similar to this

public static void LookAt2D(this Transform transform, Vector2 target)
{
    var direction = target - (Vector2)transform.position; // Get the direction
    var angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; // Convert to angle
    transform.rotation = Quaternion.AngleAxis(angle - 90, Vector3.forward); // Finally rotate the GameObject
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: serial begin 
Csharp :: get file upload file size in MB c# 
Csharp :: c# convert string to array 
Csharp :: how to edit .csproj file 
Csharp :: c# multiple inheritance 
Csharp :: unity vector3 initialization 
Csharp :: w3develops 
Csharp :: rows and columns arrays 
Csharp :: How to create a new object instance from a Type 
Csharp :: c# winforms datagridview bind to list 
Csharp :: Palindromic substrings 
Csharp :: Popup open close wpf 
Csharp :: how to compare time strings in c# 
Csharp :: oncollisionenter2d 
Csharp :: wpf databinding 
Csharp :: .net return result encoding as utf8 
Csharp :: c# new object 
Csharp :: docker-compose cassandra db 
Csharp :: c# switch example 
Csharp :: ex: c# last item in array 
Csharp :: asp.net web forms 
Csharp :: string length f# 
Csharp :: how to add a ddos api to a c# console app 
Csharp :: void on TriggerCollisionEnter2D 
Csharp :: how to make a C# game launcher 
Csharp :: unity show scene 
Csharp :: c# Class instance 
Csharp :: How to return a list to view after foreach in c# 
Csharp :: c# base vs this 
Csharp :: how to populate a collection c# 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =