Hello, I created the function rb in the start, but when i want to call it using Player1.rb. appears an error (Player1 is a gameObject that I declared it before).
What can I do? Sorry for my english
Hello, I created the function rb in the start, but when i want to call it using Player1.rb. appears an error (Player1 is a gameObject that I declared it before).
What can I do? Sorry for my english
At the top, you set “rb” to be the Rigidbody that is attatched to the Gameobject that this script is also attatched to, Not one on the player1 gameobject
If rb needs to be the rigidbody on Player1, you need to first find Player1, Then do Player1.GetComponent(), to get the rigidbody from that object
As long as the rigidbody is on the same gameObject as this script, then your FixedUpdate code should use “this.rb” instead of “Player1.rb”.
Player1.rb isn’t going to work anyways. Player1 is a GameObject and has no clue what rb is. As mentioned, you need to get the Rigidbody component from the Player1 GameObject or you need to get the script that is attached to the Player1 gameobject that has a reference to the Rigidbody component as variable rb.
Thanks to all, like for you all
First and foremost: welcome
I just wanted to quickly add that you can use code tags to directly post properly formatted code with syntax highlighting. It’s the <> button in the texteditor here on the forum, and also gets explained in the first sticky post of this subforum if you need to read up on it.
Have fun with Unity!