Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity 2d detect click on sprite

if (Input.GetMouseButtonDown(0)) {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
            
            RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero);
            if (hit.collider != null) {
                Debug.Log(hit.collider.gameObject.name);
                hit.collider.attachedRigidbody.AddForce(Vector2.up);
            }
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity script detect if in prefab edition mode 
Csharp :: c# base64 decode 
Csharp :: unity set position 
Csharp :: asp core asp for not working 
Csharp :: c# get display resolution 
Csharp :: c# mysql query 
Csharp :: c# count number of occurrences in string 
Csharp :: unity scriptable object 
Csharp :: c# iorderedenumerable to dictionary 
Csharp :: c# insert into database 
Csharp :: how to edit Camera.size property unity 
Csharp :: c# convert seconds to hours minutes seconds 
Csharp :: playerInputManager.JoinPlayer(....) 
Csharp :: unity movetowards 2d 
Csharp :: how to move your character in unity 2d game 
Csharp :: keyboard input unity 
Csharp :: c# application hangs while running 
Csharp :: c# connection string 
Csharp :: change scene unity 
Csharp :: currentTimeMillis c# 
Csharp :: C# socket bind to dns name 
Csharp :: C# how to remove an image in a folder 
Csharp :: snx disconnect linux 
Csharp :: xamarin overlay 
Csharp :: materials pink in unity 
Csharp :: c# image to byte array 
Csharp :: remove element from sting array c# 
Csharp :: elevated priviledge in c# 
Csharp :: transfer ownership photon2 
Csharp :: c# datetimepicker set weeks before today 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =