Quantcast
Channel: Latest Questions by RedDevil
Viewing all articles
Browse latest Browse all 100

Unity2D move object by touch input

$
0
0
Hi.I have this game where i instantiate a lot of 2D game objects and I want so that when i touch one of these objects that they would then start moving.The problem I am curently facing is that i get an instant crash. I curently have rigidbodys 2D and 2D circle colliders and the touch detection script on each of these objects. Here is the touch detection script from one of the objects: void Update() { if( Input.touchCount >= 1 ) { Ray cursorRay = Camera.main.ScreenPointToRay( Input.GetTouch(0).position ); RaycastHit hit; if( collider.Raycast( cursorRay, out hit, 1000.0f ) ) { this.transform.Translate(Vector2.up * 10 * Time.deltaTime); gameManager.choice = true; } } } Please help.Thank you

Viewing all articles
Browse latest Browse all 100

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>