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 :: how to edit text mesh pro text 
Csharp :: c# delete files older than 10 days 
Csharp :: how to detect mouse click in c# 
Csharp :: c# list to string comma separated 
Csharp :: c# async sleep 
Csharp :: get date of tomorrow c# 
Csharp :: how to index ireadonlycollection c# 
Csharp :: void on trigger enter 2d 
Csharp :: vue.createapp is not a function 
Csharp :: Character Controller unity isGrounded is false 
Csharp :: how to unlock cursor in unity 
Csharp :: c# write all bytes to a file 
Csharp :: c# new line in messagebox 
Csharp :: unity player look at mouse 
Csharp :: urlreferrer in asp.net core 
Csharp :: c# loop through datatable 
Csharp :: unity key pressed 
Csharp :: unity c# instantiate prefab 
Csharp :: decimal in .asp.net core 
Csharp :: how to delete folder with files on c# 
Csharp :: unity inspector how to get larger field for string text 
Csharp :: c# check if element is last in list 
Csharp :: unity serializefield 
Csharp :: how to make rb.addforce 2d 
Csharp :: c# format string with 2 decimals 
Csharp :: c sharp gun shooting 
Csharp :: on collision 2d unity 
Csharp :: read configuration workerservice 
Csharp :: vuln.c nc mercury.picoctf.net 59616 
Csharp :: how to find avareage of an array in c# 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =