Basically i’ve got a top down 2d view in which the player can move around. Enemies randomly spawn and will follow the player until they reach an adjacent square, where they will stop and spend subsequent “turns” attacking the player.
All enemies and the player take up 1 unit of space.
That part all works.
What I would like is when the player attempts to move into a square, it first checks if that square is occupied by an enemy game object. If it is occupied, the player will remain in their own square and the attack code will be carried out against the enemy.
If the square is empty the player moves as normal.
So basically is there an easy way to check if a position is occupied by a gameobject?
And then I could do:
if(squareIsOccupied){
// find out what GameObject is occupying it
// Carry out attack code against GameObject in that square.
}
else{
// Carry out movement code.
}
raycast to that position, gather information from the hit.collider.gameObject http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
– AlucardJay