Search Unity

How do I shoot a bullet at the mouse pointers position in a top down game? (C#)

Discussion in 'Scripting' started by BonBons, Jan 19, 2014.

  1. BonBons

    BonBons

    Joined:
    Jan 19, 2014
    Posts:
    5
    Hello, I am new to unity and C# and for my first "project" I am making a little top down game where you must move the ball into collectables and eventually collect enough to complete the level. I have put in a coroutine that allows me to spawn hazards at a random position every 10 seconds or so, if the player collides with one you will lose.


    For further experimentation I am hoping to allow the player to shoot a bullet at these hazards so you can get rid of them. To do this I will to have a script that allows me to shoot a gameobject to where my mouse is pointing on screen but I have no idea on how to implement this. Could anyone help me?

    Thank you!
     
  2. hektac

    hektac

    Joined:
    Nov 9, 2012
    Posts:
    28
    You could have the player script grab the location of the mouse on screen and rotate the player position to always rotate to that point. Check out the Evac City tutorial, it does this.