I am new to unity, I have watched many tutorials, made sure they are the same version of unity, I copy their scripts EXACTLY 100% and yet whenever I try simple code like
I get a error saying “an object reference is required to access non-static member UnityEngine.Rigidbody2D.AddForce”
I can solve this by making a public variable for the rigidbody and then using that variable instead of rigidbody directly. but in the videos no one has to do this. Please help!!!
Also, the word “rigidbody2D” in that code would be lower case (uppercase refers to the abstract class, lowercase refers to the component on the object) so either this isn’t true:
Or more generally, what does “doesn’t work” mean? That’s a pretty vague statement; was there a code error? (in which case, what he asked) Otherwise, what happens?
um why do you think that? The computer doesn’t just skip lines of code (unless of course that entire function isn’t being run; put in Debug.Log messages to see). What makes you think that is happening? What are you seeing when you hit Play?
In my animator speed is a float, move is a float in the code which changes between 1 and 0 when i give it input, the move float works.
in my animator Speed is used in a transition in which when greater then zero it switches from the default to a walking animation, when Speed is zero or less it swaps back.
I get no errors, nothing. the animation simply doesn’t swap when i move the player…
Okay, there are lots of possible reasons why the animation isn’t playing. You shouldn’t just jump to assuming the computer is arbitrarily skipping lines of code
One of the most common mistakes setting up animation transitions is to only go one way and forget to transition back, so check that. Also, can you post a screenshot of the animator window?
(tangent: if you’re having trouble with the tutorials you’ve found, maybe you should checkout Unity in Action)