Exzib's dev blog

1.5M ratings
277k ratings

See, that’s what the app is perfect for.

Sounds perfect Wahhhh, I don’t wanna
ERMAGERD I SOLVED IT.
Finally, this one, was a hard one.
I had to do some googling to find the solution.
So, before the fix, I would use colliders, then use OnTriggerEnter, to color the outline Cyan, set so you can pickup the object etc.
The problem...

ERMAGERD I SOLVED IT.

Finally, this one, was a hard one.

I had to do some googling to find the solution.

So, before the fix, I would use colliders, then use OnTriggerEnter, to color the outline Cyan, set so you can pickup the object etc.

The problem with that was, incase 2 batteries was close to eachother, and you pickedup one of them, the collider for the battery you picked up, didnt get exited, which basically means that you had to go away a bit, to pickup the next one.

So, I changed the system completely.

(There is a better way to do this, and it is not optimized, was in a rush.)

Started by adding a bunch of variables:

Then, I imported the pllayer transform and gameobject:

After that, I removed the OnTrigger methods, and have it all in the void Update() method.

Basicially, what the code does is that it uses Vector3.Distance, to see the distance between the battery and the player.

Then, if the distance is below the range float, it would execute some code, then I added and else to the bottom, which basically tells the system, if its not within the range, don’t do anything.

Also I use OnMouseOver and OnMouseExit to make sure that the mouse needs to be on the object!

=)

So, I was making sure everything was working, stumbled upon two problems.
Problem 1:
If I want to pickup the batteries, and they are beside eachother, I have to walk away to pick up another one, currently working on this one, its really annoying,...

So, I was making sure everything was working, stumbled upon two problems.

Problem 1: 

If I want to pickup the batteries, and they are beside eachother, I have to walk away to pick up another one, currently working on this one, its really annoying, can’t figure it out.

Problem 2:

Since I earlier made a script that  changes the intensity of the light when the light is below 15%, whenever I would reload the batteries of the flashlight, and put it on, the same low intensity that you had when you have 15% battery was shown.

I fixed this by making another if statement, that basicially does the reversed.

Another update, smaller one tho, the only change I really did this update was to add a HUD for the battery percentage.
Easy stuff, first I wanted to use a switch statement for changing the texture, but that didn’t work as I have to use less than and...

Another update, smaller one tho, the only change I really did this update was to add a HUD for the battery percentage.

Easy stuff, first I wanted to use a switch statement for changing the texture, but that didn’t work as I have to use less than and more than symbols.

So this is how it looks ATM:

I just copy pastarino the code from the ReadPage script and changed the position and size.

I might actually put this all together, optimize it and clean it up, and release it on the asset store.

Borders done and so the hover icon, yay.
I basically did the exact same on the batteries as on the paper for giving it a border.
I only modified the PickupBattery script for this.
I copypasta some code from the ReadPage script:
Then I modified the...

Borders done and so the hover icon, yay.

I basically did the exact same on the batteries as on the paper for giving it a border.

I only modified the PickupBattery script for this.

I copypasta some code from the ReadPage script:

Then I modified the OnTriggerEnter, so instead of doing this:

It goes through a for loop (As there are multiple materials on the object, changing 1 material (gameObject.renderer.material.shader =blablabla), would just change like the top, the middle or the bottom part of the battery.

So I made a for loop, which goes through all of the materials on the object. like so:

Then I did a OnTriggerExit, basically the same thing as above, just that it changes them back to Diffuse.

Then for the last part of the script, I did so instead of picking it up when you walk inside the collider, you need to press E.

Then using UFPS, I added a hover symbol:

I think this should be all for the flashlight.

Will play some hearthstone now, then check to see if everything is working as I want, then do some other stuff:

Add a pistol! :O A pistol? To a horror game?

HEHE, I HAVE IT ALL PLANNED OUT YOU SEE…

Phew.. That was a long one.
So, lets go through how I managed to add a battery pickup script.
I started by editing the BatteryScript (which handles all the percentages, batteries amounts, turning on and off light, intensity etc).
I first added a few...

Phew.. That was a long one.

So, lets go through how I managed to add a battery pickup script.

I started by editing the BatteryScript (which handles all the percentages, batteries amounts, turning on and off light, intensity etc).

I first added a few more variables, a int, which holds the battery amount, a float, which holds how many percentages each battery is, and a Audiosource, which holds the reload sound for the batteries.

When that was done, I made a new if statement in the Update method, which basically changes the amount of battery percentage depending on how many batteries you have in your inventory, then removes them etc, plays a sound and removes the batteries:

Then I tried it out and it worked great.

So now I needed to fix the battery pickup thingy.

I made a new script, PickupBattery.

There, I grabbed the script BatteryScript (the one i modified earlier), I did a OnTriggerEnter method, which executes a bunch of code when I enter the collider of the battery. (THIS WILL BE CHANGED TO “PRESS E TO PICK UP”, coming next update).

Simple.

Another update
I added a simple hover symbol so you know if you can read a object or whatever!
First I tried playing around in the settings of UFPS, but I didn’t manage it to work and I thought that I didn’t want to fuck around with the code to much,...

Another update

I added a simple hover symbol so you know if you can read a object or whatever!

First I tried playing around in the settings of UFPS, but I didn’t manage it to work and I thought that I didn’t want to fuck around with the code to much, so I decided to fix this in my custom interact script (The one which turns on the borders).

I started by importing the player gameobject and using GetComponent to find the script which handles the crosshair:

Then, whenever I press down E on the page (when im inside the collider and the mouse is over it), it will open the page aslong as I hold E, and while I’m holding E, it will disable the crosshair script.

Then I did it reversed in the if statement which says if I release the button, it will enable the script!

Now, I tried it out, worked great!

But…

Whenever I would hold E, and leave the collider, the script would be turned off.

So I fixed this by adding this simple code to the OnTriggerExit:

So now, we have a working page system, which covers opening pages, and closing them, playing sounds and having a hover icon! :D

Next thing on my list, is to add a working batteries, brb.

SUPRISE!!
More problems.
So, I was doing take 2 on the recordings of how it all worked, aaaand..
I noticed that when the mobile turns of(or the flashlight), i could turn on the light again, and have it on for an infinte amount of time!
You may...

SUPRISE!!

More problems.

So, I was doing take 2 on the recordings of how it all worked, aaaand..

I noticed that when the mobile turns of(or the flashlight), i could turn on the light again, and have it on for an infinte amount of time!

You may wonder!

HOW DID YOU SOLVE THIS IMPOSSIBLE TASK!?

Hold your hats!

I started editing in the flashlight script which holds the method that when I press “L”, it turns on the light.

I started playing around there and didn’t get it to work at all.

So, I did a very simple yet stupid fix.

Basicially, what I did was to find the FlashLight script, which holds the pressing L code, then disabled the script when the battery is below 0.

Simple fix.

Now a video will come any second because I already tested everything.