Showing posts with label Unity. Show all posts
Showing posts with label Unity. Show all posts

Friday, September 4, 2015

Easy Gridlayout in Unity 5

Hello again!  This week's tutorial on Unity's Auto Layouts is probably one of the more useful tutorials so far.  Auto Layouts are like little hidden gems in Unity's expansive engine!



Unity's UI Rect Transform layout system allows for placing of elements in virtually any arrangement.  However, sometimes a bit more structure is needed.  Unity's easy-to-use Auto Layout system provides ways to place elements in organized, nested layout groups. It also allows elements to be automatically re-sized according to the content.


In this tutorial we will explore the Auto Layout system's Grid Layout, but first let's get to know the Auto Layout system a bit better.

The Auto Layout system is built on top of the basic Rect Transform layout system. It can be used on some or all elements of a group.  The Auto Layout system has two basic components: Layout Elements - those that are nested in groups, and Layout Controllers - those that control the sizes and positions of layout elements.  For a more thorough explanation of Layout Elements and Layout Controllers visit the documentation linked in the description below.


In the Prehistoric Scroller project, I am using the Grid Layout to manage the Inventory window.  Watch as each item is added to the inventory.  As each item is added, the Grid Layout controller re-sizes and re-positions the elements of the group.



Let's look at how this is set up.  On the main camera, a second canvas is added to control the inventory.  The parent game object InventoryItems has the Gridlayout Group attached, and is considered a Layout Controller.  The Grid Layout controller has several properties to set, depending on how you want your grid to behave.

First is Padding.  This is the space on the left, right, top, or bottom **inside** the edges of the layout group. It is the same principle as Padding in the Box Model for web development. For more information on the Box Model, visit the documentation linked in the description below.

Cell Size is the size set for each element in the gird. Just like Excel, the X is the column width, and the Y is the row height.

Think of Spacing as the margin between each column, X, and row, Y.



The Start Corner is the corner where the first element is placed.  It works with the Start Axis and Constraint to control how the grid will grow.

If Upper Left, Horizontal is set, as in the Prehistoric Scroller, the next element will be placed to the right of the first cell along the horizontal axis until there are four elements in the row.  The fifth element will start a new row.



Child Alignment aligns elements if they don't fill out the available cell space.  This is similar to Paragraph alignment options.  It is important to remember the children Layout Elements have no control over their sizes.

In the Prehistoric Scroller a script enables the inventory items as the player collects them.  Let's add a Sixths item.



 Each of the inventory items are actually buttons I know I have a bone item to put into the game so  lets make this the inventory bone button. I'll speed things up as I configure the button just like normal.  Great! Now let's put the prefab bone item into the scene and see what happens. The bone inventory button displays perfectly in the InventoryItems grid!! Awesome!!

But what if you have an item that is smaller than the cell size you set on the Grid Layout controller?



Let's look at an example.  This cracked egg sprite is much smaller than the bone sprite. When I add it as a Layout Element its size is being controlled by the GridLayout controller and its scaled to be larger and doesn't really look nice.



To avoid this,I'm going to remove the button and add a blank UI Image instead. I'll add the Cracked Egg Button as a child of the Image. I'll speed things up as I format the button. Finished! Now next to the other inventory items the cracked egg looks great!

That's it!! Auto layouts, like the Grid Layout, make it easy to quickly set up organized UI in Unity. See you next time!
Read More

Monday, August 24, 2015

Easy 2D Linecasts and Their Colliders in Unity 5



Thanks for waiting for this one folks!  After moving cross country and being bugged down with a sinus infection it feels good to finally have this one published!! Let's get going!


Easy 2D Linecasts and Their Colliders in Unity 5
A line cast is an imaginary line drawn between two points in Unity's world space. Any game object with a collider can be detected and reported back if it touches the line.

In this tutorial, we will explore one  application of linecasts as well as how to set up the colliders for other objects in the scene.



In this prehistoric scroller project, we can see the T-Rex has two lines drawn from it. A long yellow line and a short red line. These lines are purely for debug purposes to give us a visual representation of the linecast start and end points. 

As the scene begins to move, we can see the T-Rex's behavior change when the yellow line touches the player's box collider.  We can see his behavior change again when the red line touches the collider.

Let's look at what is happening in the script!


The linecast only requires a start point and an end point. This is different from the similar Raycast which requires a start point and a direction but no definitive end point.  Linecast optional parameters include layermask, min depth, and Max depth. For more information on these parameters visit the documentation linked in the description below.


The RaycastHit2D reports the collider results and available information from any collider the linecast has hit! It is extremely important to note, only the first collider hit will be reported. 

Be mindful of the linecast's starting point. If it starts inside a collider, only that collider will be reported.

In the prehistoric scroller, I have the linecast start and end points update with the T-Rex's position so the linecast will move with the T-Rex.

The next part of the script controls the T-Rex's behavior based on the information returned by the RaycastHit2D.


If the yellow walk linecast hits a collider on an object named "Player" the T-Rex will begin walking towards the player and the walk animation will play. If he is not already walking.

It's important to point there is a null check wrapped around the if statement. Because this is in the update loop,if the linecast is not touching a collider every frame, the RaycastHit2D will return "null". The"if not null check" makes sure it is only called if the yellow line is touching a collider.

Also, the walk linecast is only drawn if the attack bool is false. 



Let's  look at the Attack line, the small red line. If the Attack line hits a collider on an object named "Player" the T-Rex will switch to attacking the player and the attack animation will play. If he is not already.

This bit of code sets walk to false and attack to true -  which will prevent the yellow walk linecast from being drawn.

Now that you understand how it works, let's watch it again. 

The T-Rex behavior switches from idle to walk when the player's collider touches the linecast. 

When the attack line touches the collider, the yellow walk line is no longer drawn and the T-Rex switches to attacking! Great!!

 



Now let's look at how the collider are set up. In the prehistoric scroller, the player object never moves. The Player collider is considered a Static and no Rigidbody is attached. The T-Rex does move and would be considered a Rigidbody Collider.

Because this project does not use physics, the Rigidbody is set to Kinematic and BOTH collider are Trigger colliders. A trigger simply detects when one collider enters the space of another. It reports the event not the physics.

This means the Player is actually a Static Trigger Collider and the T-Rex is a Kinematic Rigidbody Trigger Collider. 

It sounds more complicated than it is and Unity provides an awesome cheatsheet for determining if one collider will detect the other.  For a thorough explanation visit the documentation linked in the description below!!

That's it!! :D Linecasts are an awesome EASY way to detect colliders in Unity and there are an infinite number of possible ways to use them!!

See ya next time!!

Read More

Friday, August 7, 2015

Thursday, August 6, 2015

Friday, July 31, 2015

Quick Setup Scalable UI in Unity 5



Today, it is important for both designers and developers to be aware of the growing number of devices and device screen sizes available to users.  Unity's powerful UI system makes Scalable UI easy and ensures the same experience for users across devices.

In this tutorial, we will examine how quickly and easily you can set up Scalable UI for your application.

Resources: 
- Unity UI Tutorial Videos: https://unity3d.com/learn/tutorials/m...
- Unity Manual: Button http://docs.unity3d.com/Manual/script... 
- Unity Manual: Canvas Scaler http://docs.unity3d.com/Manual/script...


Read More

Thursday, July 23, 2015

Wednesday, January 7, 2015

Sunday, November 2, 2014

'Nightmares' and FPS

12:56pm



Using Unity's 'Nightmare' project tutorial for my warm up. I'll adjust the player to FP later ^_^ Great intro to the new GUI :D #7DFPS

3:29pm


This "Edit Collider" toggle button in 4.6 is pure magic.

4:15pm


#7DFPS ideas are starting to bubble

7:01pm
Whew! Still going on warm up day for #7DFPS Getting a bit antsy in  my chair but I really do enjoy the project. Especially if you are a beginner to Unity this is a great "next step" after the Roll-A-Ball tutorial

8:10pm

Done!! Great starter project and some wonderful ideas generated!!
Read More

#7DFPS Warm Up!


Hey everyone! I'm pretty excited to announce I will be participating in the 7 Day First Person Shooter game jam!  I'm starting the #7DFPS 7 hour warm-up today and pretty excited to be trying something new ^_^
I'm going to stay in Unity and probably go off some Project assets they have as it will be my first time trying the FPS genre.  This will be an awesome learning opportunity!! :D #7DFPS warm up starts now!!
Read More

Monday, July 14, 2014

Tools: GitHub & Cloud9


GitHub, the world's largest code host.  Generally terminal command line, the instantly confusing black box with white Courier font, can be intimidating.  It feels if you type one wrong command, or miss a single letter, you could destroy your entire project!  Let's face it, with all these fears you could end up avoiding the tool rather than embracing it.


Familiarity.
I find I am most scared of the unknown or unfamiliar.  Get comfortable with GitHub.  CodeSchool has an awesome course entitled "Try Git" for free.  It teaches you the basics in a very practical and immediately applicable manner.  The "Advice" box to the right of the tutorial explains the vocabulary used within GitHub.

As you progress through the tutorial, you recognize you are starting to understand what "version control" means and most importantly, how to use it.

Freedom.
While Git is social (sharable), for an independent developer it is often just you, or just me.  I don't want to be stuck in my house at a desk all day long.  What if its nice outside?  What if an awesome coffee shop/cafe just opened down the road?  What if I'm feeling lazy and want to work from the couch?  GitHub makes that super easy!  I can download my entire project in a .zip and work away.

Cloud 9 IDE


Flexibility.
Downloading and setting up an IDE can be a bit cumbersome and working from Notepad might not offer me all the flexibility I want.  Enter new tool Cloud9 IDE.  This online platform connects with your GitHub repository (tutorial).  You can customize the development environment to suit your needs, then use the console to commit just like you would otherwise.  You cannot debug in Cloud9 as C# and JavaScript are not supported languages to Run/Debug (but the awesome-est language Ruby is!!!).  Just test back at your computer with Unity installed.

Your new ease of mobility can take you anywhere!  The "home office" isn't so limited anymore.  So, what do you think?  Where would you find yourself with this new freedom and flexibility??


Read More

Friday, July 11, 2014

30 Days of C# Unity and the Lifetime Love



Hey everyone!!

The Hiatus.
Its been a while.  Let's rewind a little bit.  I started 30 Days of C# Unity in April and have since then used Unity on a daily basis.  The reason for my absence?  We needed me to learn faster.

Imagine Me.
I worked on Imagine Me, a 2D-platformer, in various roles up to this point.  On May 16, Chris and I decided to pull the plug on our current random generation system in the game.  We were not happy with it (understatement) and neither was the community.  Chris was (and is) working a full time job.  The indie dev thing is something we have done in our home life because we love it.  He didn't have the resources (time and energy) needed to rewrite the random generation AND continue development on the rest of the game.  We desperately needed a second developer.

Refined by Fire.
The job fell to me - the novice, C#-hating, Unity hesitant, just-getting-her-feet-wet girl.  I was thrown into the fire with a community full of expectations waiting on the other side.  It couldn't have worked out better.  I used the tools already enlisted from my "30 Days of C# Unity" They were a huge help and I stand behind each one listed in this blog.

Today.
Today, work is almost done with Imagine Me's new random generation.  I am tweaking a final few things to give it an appropriate feel, and prepping for adding it into the current game.  Later, I will create a "Projects" tutorial of my own to share with you, but for now my 30 Days of  C# Unity has turned into a Lifetime Love for three words: "Made in Unity".
Read More

Wednesday, April 30, 2014

Day 4 of C# Unity


It's Day 4 and I'm back to the Space Shooter!  The hands on experience with these projects has become a wonderful compliment to the Beginner Scripting lessons, but more on that later...

Project: Space Shooter
I began today's session by covering a quick review of the last video I had watched in the project.  This was very useful to 1. put my brain in "Unity" mode and 2. refresh where I had left off.  The Camera and Lighting video was an awesome refresher on Unity's orientation.  Remember: Left Handed.  I practiced orientation by putting my left hand in weird positions, then guessing what the camera would show.  It helped a lot!



The next lesson Adding a Background was pretty straight forward.  Create a quad, add texture/material, adjust shader, scale, and transform.  One cool trick I didn't know before involved dragging a texture directly onto the mesh in the scene.  Unity creates a material for you!  While creating a material yourself is not difficult, eliminating a couple steps eliminates possible errors and mishaps - always a good thing.



One thing to note, the shader step was very shallow. The reference material, provided in the links to documentation, was either too vague or too advanced. I really hope to find more on shaders and materials later.



 Moving the Player provided an awesome opportunity for me to practice the Beginner Scripting lessons from Day 3. The lesson reviewed public variables, FixedUpdate, Vector3, and rigidbody. It also provided an introduction for the next lessons in the Topics tutorials including an introduction to data types, GetAxis, and using classes.

I most enjoyed the segment on Mathf.Clamp.  This is probably the first time I've thought C# had a useful function.  Clamp is awesome.  It allows you to constrain a game object to whatever space you define, and all in just a few lines of code!



I followed along quite easily until the last segment using Quaternion.Euler.  Yikes.  When I clicked on the reference material it brought me to Intermediate Scripting.  I knew I wasn't ready for this level of scripting, but felt unsatisfied blindly typing away.



Overall the lesson was perfectly paired with Beginner Scripting.  I highly recommend using the Beginner Tutorial Scripting and Space Shooter project together.  Tomorrow is back to scripting lessons!

Have you found any useful beginner tutorials on shaders?? Please link them in the comments.  I would love to understand them better.
Read More

Monday, April 28, 2014

Day 3 of C# Unity

     

     After the weekend break, I'm back at it.  I started today with every intent to continue Unity Gems, however, I realized very quickly "Common Unity Gotchas" was a bit more advanced.  Rather than get frustrated with GetComponent and all the rules and scenarios (and a StormTrooper ??), I switched back to the Unity Topics: Beginner Scripting.

  

Beginner Scripting
     I instantly felt more comfortable.  I worked through lessons 5 - 10.  The first two were awesome "gear ups" reviewing "If Statements" and "Loops."  These bits of code in C# are not terribly different from their JavaScript counterparts.

     Lesson 7 covered "Scope and Access Modifiers".  I already knew Scope. I did not fully understand how Access Modifiers work within Unity.  In my first exposure, I might have complained about the redundancy between setting variables in scripts and then changing parameters in the Inspector tab.  I now wish I would have worked through the scripting primer from the start.

     The lesson used a variable called "alpha" as an example.  When set to public, you can adjust "alpha" in the Inspector tab.  This made so much sense now!  How convenient to be able to tweak a parameter and see the effects immediately?!   The lesson explained the value of a variable can be set in Start().  This overrides the Inspector setting, but once game play is under way, adjustments can be made in the Inspector.  What is Start()? A perfect segue to the next lesson!



     Awake() and Start() were the subjects of lesson 8.  A solid foundation of Unity requires understanding the difference, use, and timing of these functions.  I am a bit shocked I was able to finish a project without grasping how these functions work.  The script calls Awake() first, and Start() immediately before the first Update().  I had a bit more understanding of Update() and Fixed Update(), but truly enjoyed the refresher and iteration.  It does wonders for my coding confidence.

     The final lesson reviewed "Vector Maths."  I must admit how surprised I was to enjoy this lesson.  Speckled with humor, the video covers 2D and 3D coordinate basics, explains how unity is "Left Handed," and provides useful example applications  (Tank! Tank! Tank!).

  


I am loving the Unity Topics tutorials and can't wait to get back to my Space Shooter project tomorrow!



Read More

Thursday, April 24, 2014

Day 2 of C# Unity


Day Two brought me to Unity's own tutorials which they have titled Learn.  Simple and straight to the point.  Under this tab you can find Tutorials, Documentation, Live Training (if something is scheduled), and other Support options.  The Tutorials consist of Topics - specific sessions and assignments that you choose from and Projects - guided, step-by-step from set up to final build of example games.

Scripting
As I am most concerned about my scripting practices, I decided to start with the Topic: Scripting.  There are a total of 47 lessons, over half of which are for beginners.  Perfect!  The topics are a series of YouTube videos, and not interactive, but each provide downloadable code and links to reference documentation.

The first four lessons are foundation builders.  I felt they were there to make sure everyone was on the same page.  Collectively, lessons covered the concept of scripts, basic components, and best practices for conventions and syntax within Unity.  I truly enjoyed all of them.



Project: Space Shooter
If you have not yet done a Unity Projects tutorial, I highly suggest it.  By far it was the best experience for me during the Global Game Jam.  The projects allow you to get your feet wet, experience all the things, and provide links to reference material if you have any questions.

The projects come complete with all the assets you need to finish the game and are awesomely organized. This is a big plus for me as I find Unity's importing and file structure something I definitely need to learn.  I watched the videos, took notes, then completed the tasks on my own.  This helped me iterate what I was learning a couple of times. My notebook is a best friend and I often use it as a reference later.



The one downside: these projects can be a bit over the top with the hand holding.  If you just follow the steps are you really learning it?  The notebook helps, but I try and make sure I don't use it as a crutch.  I also take time to play with the tools outside of the project lesson's "scope."  A good friend of mine recently said "When you get a new tool, you should ask yourself 'How can I "break it"?' and then learn from that process."

The first few lessons in the Space Shooter give you an overview of the game you will make, orientate you with creating a new project, and give you a good understanding for creating a player game object.  Each video has a single concept that is fleshed out in a series of tasks.  I really enjoy the setup.

Day 3 is already here! Let me know if you have a similar "notebook" experience in the comments below. 


Read More

Tuesday, April 22, 2014

Day 1 of C# Unity


It's Day 1.   I have checked over quite a few tutorials and guides and will be using the following in my 30 Days of C# Unity:

Now, I must put in a bit of a disclaimer: I have been around Unity for about 6 years and this year I used Unity for the first time during the Global Game Jam.  The vocabulary and UI are somewhat familiar to me.  That said, let's begin!

Unity Gems
    I began with the "Getting Started" card and focused on "Coding Conventions."  Some of you may know I am a huge fan of the book "Eloquent Ruby" by Russ Olsen.  The closer to convention and the more beautiful I can write my code, the happier I am.  "Coding Conventions" provided an extremely helpful foundation in the form of an article.  While I prefer an interactive tutorial, I was very happy with the content and presentation of information.  One thing I didn't notice was the name of the author or contributors.  This might be a useful addition to the site as it appears to have multiple/different contributors.


Unity Cookie
    I continued my Day 1 with Unity Cookie.  This YouTube video based tutorial site was highly recommended to me by my husband ( a Unity veteran of 6+ years).  Chris said it was one of the best tutorials for "Best Practices" within Unity.  I started at the beginning with Crash Course: Learn Unity by Wes McDermott.
    I must admit videos 1.1 - 1.4 moved a little slow for me.  This is where my disclaimer from earlier is most important.  The first video began with an overview of what the next three videos would cover.  The last video was actually a recap of what videos 1.2 and 1.3 covered.  This is excellent practice when giving a talk or presentation, but as each video was divided between links it seemed a bit wasteful.
    As promised, videos 1.2 and 1.3 gave a general overview of all that is Unity 3d. Wes spent time on whiteboards before going into the Unity Editor and identifying items and ideas covered in the whiteboard sessions.  I found it a little dry, but it might be due to the fact I am familiar with Unity's basic concepts already.  If you have watched these videos I would love to hear your opinion in the comments below.  Another perspective is always appreciated.



I stopped there and will begin Unity's Learn Tutorials on Scripting and the Space Shooter project tonight.  Watch for a blog post tomorrow morning on the results!
Read More

Monday, April 21, 2014

30 Days of C# Unity


Today starts a new chapter.  As you can surmise from the title, I will begin learning a bit of C# and the Unity game engine.  I will be using a variety of learning tools, tutorials, and as always, writing a response to the day's exercises here :)  I would absolutely love it if you followed along on my 30 day journey and always welcome comments, questions, and tips.  Are you ready?  30 Days of C# Unity begins... now!
Read More