Wednesday, 4 September 2013

Unity OnGui Skin - how to assign and the gui skin with c#

So I'm caught at an awkward in between stage where I have successfully created a GUI Skin object (right click assets > create > gui skin) and my gui elements (GUI.Button(etc)), yet my gui elements are not using the skin. 

To get this working I've placed the below line of code within one of my GUI elements. 
GUI.skin = (GUISkin)Resources.Load ("MyGUI");

AND it's essential to put the GUI skin object in to the resources folder within Unity. 

Monday, 22 July 2013

MonoDevelop and Perforce - multiple save prompts issue

I thought it best to add a Perforce version control server to my files.
I am regretting rushing headlong in to this.

Downside/issue/bug - possibly just for Macs..
I am getting THREE 'are your really sure you want to save' prompts after ever edit on every document. And I cannot okay these with keyboard alone.

I don't have a fix, but my current attempted solution is to stop using Perforce... which doesn't seem to work. I am still prompted to save each item. Three times.

Solution - to stop the prompts from occurring ever more

After a bit of trial and error I've devised an approach. Sadly this involves not using Perforce. (I will later try and get this working, but for now, here's a way out).


  1. In MonoDevelop choose to compile. This is resulting in the 'Save (file) as...' dialog appearing -- the issue which I want to suppress. 
  2. Delete the original file via the file system
  3. Click 'Save' to the dialog in (1)
Voila. Dialog stops appearing on every single save. 


Calculating the angle or Quaternion between two points

So I have two sprites and I want one to face the other in a creepy Mona-Lisa-eyes-following kinda way. Just in case I fail to edit this correctly at a later stage, I should mention that I'm m  aking a 2D game, and so I'm actually only interested in rotation around a single axis. 

To do this I...

As input we have the position of two sprites in 3D space, AnnoyingSpriteFacingMe and Player.

The Quaternions is how Unity stores rotations, and so it is with these that we play.

Some code. In this example I am calculating the angle which the attacking boat should be on in 2D space in order to fire its cannons at the other boat.


public Quaternion desirableAngleForFiring(Vector3 attackingBoat, Vector3 defendingBoat){
// from a from and a to calculate the angle, then add 90
Vector3 targetDir = defendingBoat - attackingBoat;
float angle = (float) Mathf.Atan2(targetDir.x, targetDir.z) * Mathf.Rad2Deg;;
return Quaternion.Euler(0, angle+90, 0);
}


Sunday, 16 June 2013

OnMouseDown and OnGUI seem to not be working too nicely

I have an unexpected road block; I have a 2D world with GUI objects (like buttons). I click a button, 10% of the time the OnMouseDown kinda gets stuck and, after my GUI action executes successfully, sends an OnMouseDown to the world layer and a sprite responds.


THE PROBLEM
I'm using a 2012 mac book pro, where you can lightly tap the mouse or heavily tap the mouse to obtain a mouse click. The problem seems to be linked to light clicking. 

THE SOLUTION
??

MY SOLUTION
Click properly. I guess I was "using it wrong" - sorry Apple. 

Detecting something close


I need a unit to enter a zone.

For this I have added colliders to objects. Then when they collide stuff happens.

Wednesday, 22 May 2013

NavMesh Layer causing my sprites/agents to kinda vanish

I've encountered a weird problem. When I add a NavMeshAgent to an entity then place this on my NavMesh terrain then I can't see the NavMeshAgent. Well...kinda.

It's like I'm losing one of the six sides that make up the gif map.

My solution: since I'm working on a 2D game I hacked it so my units are shaped a bit differently and have a different side facing up...far from graceful, but it works.

Friday, 17 May 2013

Moving around


NavMesh seems to provide 'layers' which I can specify which sprites (/agents) can 'walk' on these. 
There is then some cool stuff built in to Unity which allows these sprites to auto-path to a location; really handy stuff to have out of the can*
*only available in pro version. 

I have also started exploring the concept of Terrain. I'm still not 100% sure on how to get my wonderful GIF in to a world that I can use. Still, I shall experiment around making a terrain a layer and seeing if I can leave it two dimensional.