I'm trying to create an attack mechanic to my player hero in my 2D Tower Defense game. When I press the Q button I want my hero to do an animation and spawn a temporary collider shaped as a cone at where the hero is looking at. If this collider collides with a GameObject called "Stone" it will decrease its hpValue with a script I made. If there is multiple Stones in the cone I want it to only effect one Stone, chosen either by random or/and closest to the hero.
How would I go about doing this and how can I detect the direction of where my hero is facing? This is my movement script:
public float speed; //Movementspeed
Rigidbody2D rbody;
void Start () {
rbody = GetComponentInChildren<Rigidbody2D> ();
rbody.freezeRotation = true;
}
void FixedUpdate () {
Vector2 movement_vector = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
rbody.MovePosition (rbody.position + movement_vector * speed * Time.deltaTime);
}