- Home /
Add force to instantiated prefabs (c#)
Here is my code that I have right now but it doesn't seem to be working could anyone explain why?
float x = player.transform.position.x;
float y = player.transform.position.y;
Vector2 origin = new Vector2(x - 3f,y - 5f);
GameObject tempObj = Instantiate(lead, origin, Quaternion.identity) as GameObject;
tempObj.rigidbody2D.AddForce(new Vector2(500f, 0f));
Doesn't seem to be working? Please be a little more specific. What behaviour are you seeing. And what behaviour would you like to see. Are there any errors?
I basically want a projectile when the mouse is clicked but all it does is create the object and doesn't apply the force to make it go forward so the object just falls until it is destroyed
Your answer
Follow this Question
Related Questions
Why is my Prefab Instantiating when the Scene is Loaded? 2 Answers
Infinity runner - best way to spawn board in runtime. 0 Answers
When flipping player, instantiated objects spawn on different spot. 2D shooting 0 Answers
Having trouble with cloning with prefabs 1 Answer
How to move Instantiated 2D objects by 0.5 using arrows(or mouse) 1 Answer