<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Farooq Azam &#187; Tutorials</title>
	<atom:link href="http://www.farooqazam.net/category/csharp/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.farooqazam.net</link>
	<description>Unity 3D, Game Development and C# Programming.</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:59:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Simple Unity Game tutorial</title>
		<link>http://www.farooqazam.net/simple-unity-game-tutorial/</link>
		<comments>http://www.farooqazam.net/simple-unity-game-tutorial/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 19:00:36 +0000</pubDate>
		<dc:creator>Farooq Azam</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Unity]]></category>
		<category><![CDATA[cube]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://www.farooqazam.net/?p=374</guid>
		<description><![CDATA[In this tutorial I will teach you how to make a simple game. This tutorial is mainly aimed at users who are new to Unity. So let&#8217;s begin. First off create a new project if you haven&#8217;t already made one. &#8230; <a href="http://www.farooqazam.net/simple-unity-game-tutorial/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-388" title="Cubes game" src="http://www.farooqazam.net/wp-content/uploads/2011/11/cube-game-300x235.png" alt="Cubes game" width="300" height="235" /></p>
<p>In this tutorial I will teach you how to make a simple game. This tutorial is mainly aimed at users who are new to Unity. So let&#8217;s begin.<span id="more-374"></span></p>
<p>First off create a new project if you haven&#8217;t already made one.</p>
<p>Right-click inside your Project tab and click Import Package &gt; Character Controller. Click on &#8220;none&#8221; at the bottom left and scroll down to the bottom. Under Scripts tick &#8220;MouseLook.cs&#8221;. This will import the MouseLook script. It will help us rotate the camera around using mouse movement.</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/import-package.png"><img title="Import package" src="http://www.farooqazam.net/wp-content/uploads/2011/11/import-package.png" alt="Import package" width="679" height="364" /></a></p>
<p>Now that we&#8217;ve got the MouseLook script let&#8217;s attach it to our camera. Select the <em>MainCamera </em>in the <em>Hierarchy</em> and in the top menu go to Component &gt; Camera-Control &gt; MouseLook. Viola! Now if you play the game you can rotate the camera around by moving the mouse but our scene is empty and all you see is a blank blue background. Let&#8217;s design a simple level.</p>
<p>In the top menu go to GameObject &gt; Create Other &gt; Plane. In the<em> Inspector</em> set its x/y/z position to &#8220;0&#8243; and set its x/y/z scale to &#8220;2&#8243;, so our camera can see it. Hit Play and now you can see that if you move the mouse the camera will rotate!</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/plane.png"><img class="alignnone size-full wp-image-393" title="plane" src="http://www.farooqazam.net/wp-content/uploads/2011/11/plane.png" alt="" width="727" height="550" /></a></p>
<p>But its pretty dark in here, isn&#8217;t it? Let&#8217;s add a light so we can see things a little better.</p>
<p>Go to GameObject &gt; Create Other &gt; Point Light and use the following values:</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/point-light.png"><img class="alignnone size-full wp-image-384" title="Point Light" src="http://www.farooqazam.net/wp-content/uploads/2011/11/point-light.png" alt="Point Light" width="289" height="347" /></a></p>
<p>Play the game and you&#8217;ll see its not dark anymore.</p>
<p>So, now we&#8217;ve got a simple level and we can rotate the <em>Camera </em>using the mouse! But that&#8217;s not interesting. Let&#8217;s add some stuff we can interact with.</p>
<p>Go to GameObject &gt; Create Other &gt; Cube and in the <em>Inspector</em> set its x/y/z position to &#8220;X: 0, Y: 0.5, Z: 0&#8243;. Next go to Component &gt; Physics &gt; Rigidbody to make it a Rigidbody. Now it will be affected by gravity and it will respond to collisions with real time Physics etc. You can read more about Rigidbodies at the <a href="http://unity3d.com/support/documentation/Components/class-Rigidbody.html">Unity Documentation</a>.</p>
<p>Go to Edit &gt; Duplicate and make 5 copies of it so you&#8217;ll have 6 cubes in your scene. Position them like this:</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/cubes.png"><img class="alignnone size-full wp-image-385" title="Cubes" src="http://www.farooqazam.net/wp-content/uploads/2011/11/cubes.png" alt="Cubes" width="500" height="378" /></a></p>
<p>Now we&#8217;re gonna make the player throw a ball. Go to GameObject &gt; Create Other &gt; Sphere. We want the ball to be affected by gravity and want it to collide with cubes. So add a Rigidbody to it by going to Component &gt; Physics &gt; Rigidbody. Position the ball right in front of the cubes but not too close the cubes.</p>
<p>To make the player throw the ball we&#8217;ll need a script. In the Project tab click on Create &gt; Javascript, name it &#8220;ThrowScript&#8221;. Double click to edit the script and use this code:</p>
<pre class="brush: plain; title: ; notranslate">
// This variable will contain a refernce the ball
var ball : GameObject;

// Speed of the ball
var speed : float = 800f;

function Update ()
{
	// If the Space key is pressd, apply force on the ball in z-axis (forward)
	if(Input.GetKeyDown(&quot;space&quot;))
		ball.rigidbody.AddForce(0, 0, speed);
}
</pre>
<p>We&#8217;re almost done. In the <em>Project</em> tab drag the ThrowScript and drop it over the <em>MainCamera </em>in the <em>Hierarchy </em>to attach it to the camera. All we need to do now is to tell the script which ball to use. Select the <em>MainCamera</em> and scroll down to the ThrowScript in the Inspector and drag and drop the Sphere into the Ball variable.</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/camera-throw.png"><img class="alignnone size-full wp-image-387" title="camera-throw" src="http://www.farooqazam.net/wp-content/uploads/2011/11/camera-throw.png" alt="" width="600" height="454" /></a></p>
<p>That&#8217;s it! Our simple game is now finished. Play the game and press space and you&#8217;ll see how the cubes react when the balls collides with them.</p>
<p><a href="http://www.farooqazam.net/wp-content/uploads/2011/11/cube-game.png"><img title="Cubes game" src="http://www.farooqazam.net/wp-content/uploads/2011/11/cube-game.png" alt="Cubes game" width="573" height="450" /></a></p>
<p>If you have any questions or tutorial requests post a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.farooqazam.net/simple-unity-game-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

