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);
}
Also in C#:
- c# md5 int
- .net core get image from url
- vb.net tostring numeric format string
- covert char[] to string C#
- unity delete all children
- kill child C#
- 2d object look at object
- asp.net core mvc not triggering client side validation
- c# double value with 2 decimal places
- move file from one folder to another c#
- unity html request
- convert array object to int[] c#
- unity get scrollbar value
- c# keyvaluepair
- devexpress objectspace to session
- invalidoperationexception c# ui thread
- how to close a form c#
- c# make http request
- add spaces between words unity
- get variable from another script unity
- return random from enum
- c# new list object
- add row and columns to grid wpf in code
- list c#