Hello,
i followed a tutorial to make my own "flappy bird(game on android) "clone but a script
form the video gives me an error message(only as soons as i start the game):
MissingComponentException: There is no ‘Rigidbody2D’ attached to the “PlayerBird(Clone)” game object, but a script is trying to access it.
You probably need to add a Rigidbody2D to the game object “PlayerBird(Clone)”. Or your script needs to check if the component is attached before using it.
UnityEngine.Rigidbody2D.get_velocity () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/Physics2DBindings.cs:1194)
GroundMovement.FixedUpdate () (at Assets/Scripts/GroundMovement.cs:20)
The problem is there is no “PlayerBird(Clone)” and the GameObject “PlayerBird” has a Rigidbody2D.
I found out that if i set the code in the “FixedUpdate()” as a command, the error disappears.
using UnityEngine;
using System.Collections;
public class GroundMovement : MonoBehaviour {
Rigidbody2D player;
void Start () {
GameObject player_go = GameObject.FindGameObjectWithTag("Player");
if(player_go == null) {
Debug.LogError("Couldn't find an object with tag 'Player'!");
return;
}
player = player_go.rigidbody2D;
}
void FixedUpdate() {
float vel = player.velocity.x * 0.75f; // this code as comment repairs everything
transform.position = transform.position + Vector3.right * vel * Time.deltaTime; // this code as comment repairs everything
}
}
I don’t know what to do because there is no “Clone” and the Rigidbody2D is attached to the normal GameObject.
