Fast Tutorial: How to do a gradient bar?

Hi readers!

    This is the first post tagged with #ft tag, so I will do a little explanation about it before start with the tutorial: This tag will be in tutorials that they explains little tips or fast things, so they will be short and useful! Amazing!

    OK! Now, we can start with the tutorial so let's go! How to do a gradient bar? A gradient bar is used in games for score, health... currently I am using the following code in the development of a game, so if you have any problem, post a comment and I will answer you as soon I can.

    Our objetive is do this:

http://codenauta.blogspot.com

    We only need to follow few steps:
  1. Create a plane and scale it to seem like a progress bar
  2. Create a new script called GradientBar ,paste the code posted at the end of the post, save the file and add this script to the plane
  3. Press Play Button to start debug, and press Space Key to show our amazing Gradient Bar!
    If you have any problem or you want to say something post a comment or say something in my Twitter (@Mr_Nauta).
    Here is the code of GradientBar script:


//Code created by @Mr_Nauta and posted in http://codenauta.blogspot.com
//If you have any question please ask me in a comment or ask me in my Twitter: @Mr_Nauta
//You can use this code in your project but I like that I will appear in credits or thanks :)

using UnityEngine;
using System.Collections;

public class GradientBar : MonoBehaviour {
 private Texture2D bar_tex;//This is the texture of the progress bar

 int c=100;//This variable is only for testing, while is pressed space key it will decreased by 1 (see Update() function)

 void Start () {
  //Create a new texture (100 width, 1 height)
  bar_tex = new Texture2D (100, 1);
  //With these options the texture will be automatically resized without code
  bar_tex.filterMode = FilterMode.Bilinear;
  bar_tex.wrapMode = TextureWrapMode.Clamp;
  //Apply changes in the texture
  bar_tex.Apply();
  //And set this texture as the main texture of our progress bar (a basic plane object)
  renderer.material.mainTexture = bar_tex;
 }

 //This function is only used for testing and can be deleted
 void Update () {
  //If is pressed the space key...
  if (Input.GetKey("space")) {
   //If c is more than 100...
   if(c>100)
    //We set it to 100
    c=100;
   //If c is between 100 and 0...
   if((c<=100)&&(c>-1)){
    //Set pixel at coordinates c,1 (c is the width and 1 the height (height is constant because our texture is only 1 of height))
    bar_tex.SetPixel(c,1,GetBlendedColor(c));//GetBlendedColor is our main function and only need the percentage of the progress bar in base 100 like 9% or 21%
    bar_tex.Apply(); //Apply changes
    c--;//And decrese by 1 c variable
   }
  }
 }
 public Color GetBlendedColor(int percentage){
  //If percentage is less than 50
  if (percentage < 50) {
   //Call interpolate function between colors green and yellow, and parsing the total percentage of the progress bar to a custom percentage (see our TransfromPercentage function for more info)
   return Interpolate(Color.green,Color.yellow,TransformPercentage(percentage));
  } else {
   //If is more than 50 call interpolate function with colors yellow and red
   return Interpolate(Color.red,Color.yellow,TransformPercentage(100-percentage));
  }
 }
 public float TransformPercentage(int p){
  //This function divide our 100 per 100 progress bar in 2 "virtual" progress bar:
  //-> 1 progress bar of 100 point between 0 and 50
  //-> Other progress bar of 100 point between 50 and 100
  //And also transform that value in a float value, transforming the value from base 100 to base 1, for example:
  //In our 100 per 100 progress bar we have this percentage: 23%
  //Our final value will be: (23/100.0)*2.0
  //Other example, in our 100 per 100 progress bar we have this percentage: 86%
  //Our final value will be: ((100-86)/100.0)*2.0
  return (float)((p / 100f) * 2f);
 }
 public Color Interpolate(Color c1,Color c2,float p){
  //This function use a Unity function called color lerp that need three arguments;
  //c1 and c2 (interpolated colors)
  //p The percentage of interpolation in our situation
  return Color.Lerp(c1,c2,p);
 }
}

If you prefer, I have done a Unity Package with an example scene and this script that you can download in the following link and test it:



Vacances, the worst thing for a blog

Source: http://lacocinadebender.com/wp-content/uploads/2010/09/vagos+garfield.jpg

Hi everyone!
Summer, the beach, more time to relax, more time to program, more time to write? It will be perfect but in summer everybody is too lazy to write in a blog so I wanted to write here but I couldn't (if you know what I mean).

But now, it is time to change, because I want to publish a lot of articles and news that me and my team (NebuTech team, please see here for more information: http://nebulatechco.blogspot.com) are doing!

So, let's go to work! First, I will publish at less an article each two days (a tutorial, or something like that, not  a post like this).

Second, I will do some publish (:P) so if you want to have the last updates, you should follow me in Google+ and Twitter (yeah, this is publicity, but why not?):

I hope see you in these social networks or posting here every question that you have!


Arkanoid Game Tutorial: Part I

arkanoid game tutorial part 1

But... what is Arkanoid?

Arkanoid  is a very famous is an arcade game developed by Taito in 1986. As the English Wikipedia says: "The player controls the "Vaus", a space vessel that acts as the game's "paddle" which prevents a ball from falling from the playing field, attempting to bounce it against a number of bricks. The ball striking a brick causes the brick to disappear. When all the bricks are gone, the player goes to the next level, where another pattern of bricks appears. There are a number of variations (bricks that have to be hit multiple times, flying enemy ships, etc.) and power-up capsules to enhance the Vaus (expand the Vaus, multiply the number of balls, equip a laser cannon, break directly to the next level, etc.), but the gameplay remains the same.
At round 33, the final stage, the player will take on the game's boss, "DOH", a head resembling moai. Once a player reaches round 33, he must defeat DOH with his remaining extra lives because there are no continues on the final round."

Let's start!

Ok, now we know what is Arkanoid...but what are we going to do? We are going to do a port of that game (yeah, there are a lot of ports of this game but our port is spceal: it will have been made by us :P), a simple and easy port but it will be funny and that is the most important thing, no?

What are we going to use?

We are going to use these tools:
  • Unity (I will use Unity Pro v.4.5.1f3
  • Paper (yes, a normal paper where I will draw and design, but you can use for example Paint)
  • Photoshop (or Gimp, for design graphics and textures)
  • And the most important thing: a brain
Go, go, go!

Once you have all of these "tools" we can start to develop this awesome and amazing project :P. So open Unity and create a new project importing the assets that you want to use (at the begining I won't import any asset) and remember to set defaults for 2D!

Now, open Photoshop or Gimp and start to design these textures:


  • One texture for the spaceship
  • One texture for the common block, for example a grey spaceship
  • Seven textures for the special weapons that you can obtain for your spaceship on each level
  • One texture for the ball
If you don't know (or you are too lazy ;), you can dowload my textures at the end of the post.
Now, let's go to Unity and create a new folder called Textures where you should place the textures that you have done.

Warning! Remember to set the properties of the textures like this:

  • For the ball (if you use alpha channel): 


  • For the blocks:


Link to dowload my textures:


Conclusion

So, now we have done textures and we have created the project. In the next part of the tutorial we will start with the basic movement of the ball and also with some weapons for the spaceship.
I will post here the link to the next tutorial when it will be published! Please share it in Facebook and Twitter at the buttons below!

Started with Unity Tutorial!

http://www.fiverr.com/warrior_alpha/program-unity-scripts

Hi! After a lot of time without publish in this blog, I think that is a good moment to continue, and I come with a lot of news!

I have been working doing some games and apps in Unity (I am preparing a portfolio to show it ;) and I started to sell my work in Fiverr doing these works:

  • Programming scripts
  • Programming games (in 2D or 3D for all the platforms that Unity supports) with its graphics, sounds and other stuff...
  • Teaching about how to use Unity
  • Teaching about how to use whatever Unity asset
  • Etc...
So, in few days I will submit here a Unity webplayer showing some of the scenes that I have done for teach Unity and Unity assets, so if you want to have good classes about Unity or some Unity asset you can buy my GIG (link below) (Note: The best thing in Fiverr is that is too cheap, so you will have Unity classes or Unity asset tutorial for less money than in other websites ;), so if you want...come here and start to learn!


Note: If you prefer, I also can teach in Spanish, only ask for it in my Fiverr webpage ;)
If you liked it, please share in Twitter and Facebook!


[SOLUTION] Unity with Windows 8.1 64 bits doesn't work

It is posible that you updated your Windows 8 to your fantastic new version of Windows (Windows 8.1) and then open Unity to continue working in your game and in that moment...

Crash! Yes, Unity crash and you say: "This should be a problem, but let's go to try again...", then you try the compatibilty mode, but nothing... Unity doesn't want to work!

Okay, and what is the solution? Downgrade my Windows? No! It is not necessary, you only need to follow these three steps and the problem was gone to the past:


  1. Right-click over the shorcout to Unity and click in Properties
  2. Search for a textbox which has text like this: "C:\Program Files (x86)\Unity\Editor\Unity.exe"
  3. Replace that text for that: "C:\Program Files (x86)\Unity\Editor\Unity.exe" -force-d3d11 and close
And it is done! If you try now to open Unity, Unity will work without problems and it shouldn't crash.
I hope that it will work for you!

The first post!


          Always, when I start to write a blog, I think about if it will be a famous blog or it will be a interesant blog...
But today not, today I start this blog with only one purpose: to make a dev diary about my programming learn, and show to Internet my amazing and awesome projects (:P)!

         In conclusion (yes, I know it, this post is too short), I hope that my future post will be very interesant for you and also for me, I hope that I will learn a lot and also that I will teach you a lot...

         Good bye!

(C) 2014 Mister Nauta. Con la tecnología de Blogger.