Question by
hakudemon · Nov 25, 2018 at 10:22 PM ·
scripting problemspawn
Im having trouble shooting to the mouse location on screen
I'm trying to get my game to shoot correctly using the following script attached to a camera. (bit of a scrub here)
{ Vector2 clickPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 dir = clickPos - (new Vector2(transform.position.x, transform.position.y)); dir.Normalize(); GameObject bullet = Instantiate(projectile, transform.position, Quaternion.identity) as GameObject; bullet.GetComponent().velocity = dir * bulletSpeed; } << I have my game object for the bullet name projectile in the prefab section but feel like i've hit a brick wall. I want the bullet to go from the camera location to the mouse location. any help would be greatly appreciated. Thanks!if (Input.GetMouseButtonDown(0))
Comment
Your answer
Follow this Question
Related Questions
spawn 1 enemy and once destroyed spawn another= 2 Answers
How can I modify all gameobjects that have the same script just 1 time? 0 Answers
error CS1526: A new expression requires () or [] after type 1 Answer
how can I add a maximum of enemies to be generated for each wave? 0 Answers
"InvalidCastException: Specified cast is not valid. (wrapper castclass)" ERROR 0 Answers