Script Debugging Android Games in Visual Studio

It is common knowledge that I work on mobile games and of course Android is one of the platforms we develop on. And from time to time we need to break point our code whilst it is running on device. Today however, I couldn’t remember how you do it. So I headed over to the Unity Manual, but there was lack of information how to do this in Visual Studio. It tells you how to easily attach to the MonoDevelop debugger, but not the Visual Studio one. So we went looking for a way to do it. Unity Answers post does tell you how to do it, but it isn’t particularly well worded and also starts of with “I just went back to MonoDevelop” which quickly makes you stop reading the rest of his/her answer.

This is how you do it.

First follow the steps on this page of the manual:

Then in Visual Studio go to the following menu:


In the next Window you should see “Android Player” (you don’t see it in the next image because I am not currently working in an Android project, but hopefully the giant arrow will help).



If you have an IP of a device you can also input it here. This also works for some of the other platforms including some of the consoles.


Basic Melee Combat in Unity

Soooo you know how I did that big post about how I was stopping work on my stealth-action game. Welllll something drew me back.

One of the things that caused my to stumble last time was that I had never worked on a melee combat system, but I had an idea of how to do it today. Sometimes I find context switching and working on something else for a bit causes some sort of brain wave on other bits of work. Interesting huh.

Anyway, this is how I went about it. First I found the bone for  the weapon in our player characters hirearchy and added a box collider, setting it to use a trigger and also added a rigidbody.


I then made a PlayerMeleeAttackScript that looks like this.


Essentially, when the X button is pressed on the 360 controller, this tells the animation script to attack. I then wrote the following script that triggers the damage logic on an enemy when a trigger collider intersects with a gameobject that has the “Enemy Damage” script attached.


And attached it to the bone gameobject where I added the box collider.

Now because the script is attached to the bone that moves during the animation, when the attack animation is played, the collider moves as well and when the trigger intersects with an enemy, the logic is performed.

The result is you get something like this.


It is super basic, but it works!



Overriding clips in the animator through code

Unity did a nice post recently on Recore’s animation system with the layered state machine, which reminded me of something cool I have done in games before and something cool I am doing int my personal projects.

Before we get started you should read up on:

Awesome, OK here is the scenario. Say you want are making a JRPG like I am Setsuna (pictured above) and say for each ability you want the character toperforma a different character animation. Not one per character, a different character animation per ability. It would be pretty mental to set up a layer per ability they can use. Also what if you were making one of those fancy games-as-a-service and wanted to add cool abilities later on without doing a binary update. Here is one approach.

Firstly I have created this basic state machine for the characters (notice there are no transitions)


And I have created the corresponding override controller that has the default clip in the use ability slot


We are going to override this in code using the following utility function:


Now if you run the animator controller and the name of the state, and the clip you want the Use Ability state to play into this function, Unity will play the clip you loaded in!

Neat huh!