Skip to main content

Posts

Featured post

How to Create Field of View mesh dynamically in unity

Hi Guys,

Finally, I got a chance to try my hands on an RTS game. I am a big fan of 'Behind enemy line' so my first intention was to develop something like that.

Making AI move around was easy. The Second part was tough, where you need to detect player when it comes under enemy Field of view (FOV).

It was again easy to develop an FOV using raycast but I was not sure how to make FOV mesh. And my requirement was to make the mesh dynamic, so if there is an object in front of my enemy than FOV mesh should not go through it.

As we all know how helpful is Unity community. This time also I got a lot of help from them and this post is just a token of respect for all of you guys who helped me achieve this. I am sharing the project file for you guys, Have fun!


Here is a video showing how my dynamic FOV mesh works.




Here is the project file : LINK



IF you find this post useful, you can contribute by clicking the link Given Below.
https://www.paypal.me/Sushanta1991
Recent posts

Generic Swipe control for unity

Hi Guys,

Its been a long time since i posted anything, This time i am going to post something very useful but this time its more clean and inheritable.

You can inherit this Swipe Control script to any of your child classes and do task related to that child object. I will put an example below.


Enjoy!




using UnityEngine;
using System.Collections;

publicclassSwipeControll:MonoBehaviour
{
publicboolActive=true;

publicboolSwipeVertical=true;
publicboolSwipeHorizontal=true;

publicfloatminSwipeDistY;
publicfloatminSwipeDistX;
[HideInInspector]
publicboolHitSwipe=false;
protectedVector2startPos;



publicvirtualvoidActionUpSwipe()
{
//Debug.Log("SwipeUp");
}

publicvirtualvoidActionDownSwipe()
{
//Debug.Log("SwipeDown");
}

publicvirtualvoidActionRightSwipe()
{
//D

How to create a carousel view with Unity UI

Hi Guys,

In my last project i was asked to add a carousel view in one of the screen, But as you know unity doesn't provide anything like that, so i created my own solution.

If anyone need it than you can download the project file from the link given below.


Here is a video showing how my Carousel view looks like.



Here is the Project File link : http://bit.ly/2gRybKZ

And if you find this post useful, you can contribute by clicking the link Given Below.
https://www.paypal.me/Sushanta1991


Good Luck!

How to create Chat Screen with new Unity UI

Hi Guys,

Unity UI is a blank page you can create anything you want, but some time it needs a lot of effort, and this one took a lot.

Anyways, i was successful in creation of an UI which looks similar to WhatsApp or any modern chat application.

All you need to do is pass a string to a Coroutine, separated by  "~0" and "~1" based on these separators function decides where to put the text on screen (left/right side).

So, i am not gonna post any script here, I will attach the Project file itself so you can check things in detail. There is only 2 scripts, all the logical part is handle by ChatManager.cs.

if you have any doubts, please feel free to ask.





Basically the setup looks something like this.






If you like this post and want to contribute Please click on the link given below.
https://www.paypal.me/Sushanta1991

Project File Link :http://bit.ly/2fdx2tZ

How to merge 2 Texture in unity

Hi guys,


Finally i got a chance to play with pixels, i was trying make an image effect. In the process i faced some challenges, so this post is about one of the challenges i faced.


I was trying to make a 'Vignettes' Image effect, to do that i needed to merge my overlay with the background image, this was little bit tricky at first. There was very less information available on the internet, though 'wikipedia' came to the rescue. I found this article which have a simple formula that merges 2 texture.


So the formula was,


Looks complex right ? lets read that formula as a sentence,
outputRed = (foregroundRed * foregroundAlpha) + (backgroundRed * (1.0 - foregroundAlpha));

Now it makes more sense, so basically you need to use that formula to get red, green and blue values of each pixel and create a new texture with that.

foreground is the overlay i created, which is a transparent texture, and my background is opaque.


background


foreground (overlay image for Vignettes effect)



I m…

How to rotate a 2D Vector in unity

There are hundreds of posts on this topic, but i will specifically stick to unity only. Since i struggle a little bit to figure out how vector's work's in unity, so i don't want this to happen with you guy's.


Few day's back i was simply trying to rotate a 2D vector in unity , just to create a circle.

I found this equation in wikipedia , which rotates a vector




First i tried to rotate a simple vector which was pointing at (2,0) to 90 degrees at (0,2), take a look at the image :




So i took the equation, and tried it in unity, which looks like this :

publicVector2RotateVector(Vector2v,floatangle)
{
float_x=v.x*Mathf.Cos(angle)-v.y*Mathf.Sin(angle);
float_y=v.x*Mathf.Sin(angle) +v.y*Mathf.Cos(angle);
returnnewVector2(_x,_y);
}

If i pass RotateVector(new Vector2(2,0), 90), I should get a Vector(0,2) but unfortunately i was getting something like this (-0.9, 1.8) .



If you read the Unity Documents carefully they have said that Sin and Cos function takes the value in Radian, so w…

How to use webcam in unity new UI

Hello! guys...

welcome to another post on UI :)

so in my last project there was a requirement of creating a selfie screen in unity, so i used new UI to create it.

There was some challenges but as always unity community was very helpful, that is the reason i thought of sharing my experience here in this blog.

My setup in unity was really simple, I used rawImage and assigned webcamTexture to its  texture   property, and that's it, once you call webcamTexture.Play(); you will get the realtime feed from camera in your rawImage.

here is an image showing my setup.



you can see that, my rawImage width is larger than its height, thats because my webcamTexture width was larger than its height, so if i keep it in square shape, my image was getting stretched, so thats why i kept it like that.

But to tackle this problem i am cropping my final texture to a square shape, based on smaller width /height, which gives me a perfect square shape image without any stretching.

here is a sample of my f…