- Home /
Add Force when level loads
#pragma strict
function Awake () {
if (Application.loadedLevelName = "menu") {
Rigidbody2D.AddForce(Vector2.up * 100);
}
}
I am currently making a 2d game which I am designing the menu for. For my background, I have dots floating around. To do this, I added colliders past the edges of the screen. However, this code block will not run. If anybody can find errors it would be greatly appreciated. Thank you
What is this script attached to? What do you expect it to do? Why are you setting loadedLevelName, did you mean ==?
Answer by JacobHockey13 · Mar 28, 2014 at 03:01 AM
Sorry I just figured out the problem i used Rigidbody2D instead of rigidbody2D this and changing = to == runs the code Thank You
Answer by JacobHockey13 · Mar 28, 2014 at 02:56 AM
I did fix the = to == and now I am only getting error BCE0020. I want the dot(s) to to be propelled into motion when the menu loads up so that there are dots flying in random directions (opposed to a bland white background). Here is an image
U should add rigidbody2d to your game object that also holds this script. At bottom of game object inspector panel is a tab named "Add Component" , click that and find Physics> Rigidbody2D. This will add a 2d rigidbody to your game object and sort that error out. Take care bud. Gruffy
Your answer
Follow this Question
Related Questions
Add force once when object is created 1 Answer
Why is velocity checking intensive? 0 Answers
How to move a rigidbody along a curve or spiral 0 Answers
AddForce to position on Rigidbody 2 Answers
Rigidbody Addforce cancels out Rigidbody velocity..maybe? 0 Answers