Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Unity Make a 2D object look at the mouse position

public class LookAtMouse : MonoBehaviour
{
    void Update()
    {
        Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        
        Vector2 direction = mousePosition - transform.position;
        float angle = Vector2.SignedAngle(Vector2.right, direction);
        transform.eulerAngles = new Vector3 (0, 0, angle);
    }
}
Comment

unity 2d how to set an object or the mouse position

    Vector2 mousePos = new Vector2(camera.ScreenToWorldPoint(Input.mousePosition.x), camera.ScreenToWorldPoint(Input.mousePosition.y));        
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# check to see if dictionary key exists 
Csharp :: unity how to set an objects postion x,y,z 
Csharp :: string to int c# unity 
Csharp :: how to convert int to string unity c# 
Csharp :: blazor get current url 
Csharp :: c# count files in directory and subdirectories 
Csharp :: how to download file from url using c# 
Csharp :: c# linq extension methods left join 
Csharp :: rigidbody2d unfreeze position 
Csharp :: linux command line exit with error message 
Csharp :: c# loop through datatable 
Csharp :: c# get last character of string 
Csharp :: format phone number in c# .net 
Csharp :: find closest gameobject unity 
Csharp :: newline in button wpf 
Csharp :: asp core asp for not working 
Csharp :: move gameobject in unity 2d 
Csharp :: check animation end unity 
Csharp :: unity remove gameobject 
Csharp :: c# form formborderstyle none move 
Csharp :: raycast unity 
Csharp :: c# System.Resources.MissingManifestResourceException error 
Csharp :: oncollisionenter unity 
Csharp :: c# connection string 
Csharp :: how to update a project to cross target .net core 
Csharp :: discord bot time C# 
Csharp :: if exist TempData[] c# 
Csharp :: unity object walkable not working 
Csharp :: unity cinemachine lock camera axis 
Csharp :: Codewars Multiply 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =