{"id":1125,"date":"2015-01-12T13:30:05","date_gmt":"2015-01-12T13:30:05","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1125"},"modified":"2015-08-16T19:48:24","modified_gmt":"2015-08-16T19:48:24","slug":"unity3d-brick-shooter","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/codeproject\/unity3d-brick-shooter\/","title":{"rendered":"How to create a Unity3D Brick shooter step by step"},"content":{"rendered":"<p>Followed\u00a0<a href=\"http:\/\/unity3d.com\/learn\/tutorials\/modules\/beginner\/physics\/assignments\/brick-shooter\">this<\/a>\u00a0official tutorial, my own version on\u00a0<a style=\"color: #bc360a;\" href=\"https:\/\/github.com\/Hitman666\/Brick-Shooter\">GitHub<\/a>, and you can\u00a0<a style=\"color: #bc360a;\" href=\"http:\/\/nikola-breznjak.com\/_testings\/Unity\/BallShooter\/\">see it in action here<\/a>\u00a0(WSAD to move, mouse click to shoot).<\/p>\n<p>Steps on how to create this:<\/p>\n<ol>\n<li>Create a new 3D project<\/li>\n<li>Save the scene as\u00a0<em>Main<\/em><\/li>\n<li>Create -&gt; 3D object -&gt;\u00a0Plane<\/li>\n<li>Create -&gt; 3D object -&gt;\u00a0Cube\n<ol>\n<li>Add Component -&gt; Physics -&gt; Box collider<\/li>\n<li>Add Component -&gt; Physics -&gt;\u00a0Rigidbody<\/li>\n<li>Drag and drop this object in the Assets\/Prefabs folder<\/li>\n<li>Make duplicates (use snapping to move by using the ctrl key)<\/li>\n<li>Make a row of them (about 8) and then make a new empty object and drag them all into this object<\/li>\n<li>Now duplicate this object and position above (again by using snapping with ctrl key)<\/li>\n<\/ol>\n<\/li>\n<li>Create -&gt;\u00a03D object -&gt; Sphere\n<ol>\n<li>Add Component -&gt; Physics -&gt; Sphere\u00a0collider<\/li>\n<li>Add Component -&gt; Physics -&gt; Rigidbody<\/li>\n<li>Make it into a prefab<\/li>\n<li>Delete it from Hierarchy<\/li>\n<\/ol>\n<\/li>\n<li>On the camera object =&gt; Add Component -&gt; Script:\n<ol>\n<li>\n<pre class=\"lang:default decode:true\">#pragma strict\r\n\r\npublic var projectile : Rigidbody;\r\npublic var shotPos : Transform;\r\npublic var shotForce : float = 1000f;\r\npublic var moveSpeed : float = 10f;\r\n\r\n\r\nfunction Update ()\r\n{\r\n    var h : float = Input.GetAxis(\"Horizontal\") * Time.deltaTime * moveSpeed;\r\n    var v : float = Input.GetAxis(\"Vertical\") * Time.deltaTime * moveSpeed;\r\n    \r\n    transform.Translate(new Vector3(h, v, 0f));\r\n    \r\n    if(Input.GetButtonUp(\"Fire1\"))\r\n    {\r\n        var shot : Rigidbody = Instantiate(projectile, shotPos.position, shotPos.rotation);\r\n        shot.AddForce(shotPos.forward * shotForce);\r\n    }\r\n}<\/pre>\n<\/li>\n<li>Drag the Sphere\u00a0prefab to the projectile<\/li>\n<\/ol>\n<\/li>\n<li>Create empty game object and rename to <em>shotPos<\/em>\n<ol>\n<li>drag and drop it on the camera<\/li>\n<li>reset transform origin<\/li>\n<li>Position y=-0.5, z=1<\/li>\n<li>Rotation x=-15<\/li>\n<\/ol>\n<\/li>\n<li>Drag Camera to shot pos variable in the script<\/li>\n<li>If you want to clean up the bullets after 2 seconds, add script to Sphere prefab:\n<pre class=\"lang:default decode:true\">function Start () {\r\n\tDestroy(gameObject, 2f);\r\n}<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Followed\u00a0this\u00a0official tutorial, my own version on\u00a0GitHub, and you can\u00a0see it in action here\u00a0(WSAD to move, mouse click to shoot). Steps on how to create this: Create a new&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1126,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,41],"tags":[],"class_list":["post-1125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codeproject","category-unity3d"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1125"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1125\/revisions"}],"predecessor-version":[{"id":2098,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1125\/revisions\/2098"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/1126"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}