Question by
SoldierIke · Mar 10, 2018 at 06:45 PM ·
c#errorprefab
My GetComponent is not working.
public class Bird : MonoBehaviour {
public float upForce = 200f;
private bool isDead = false;
private Rigidbody rb2d;
// Use this for initialization
void Start ()
{
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update ()
{
if (isDead == false)
{
if (Input.GetMouseButtonDown (0))
{
rb2d.velocity = Vector2.zero;
rb2d.AddForce(new Vector2(0, upForce));
}
}
}
}
I need help, it keeps giving me the same message, CS0029 C# Cannot implicitly convert type to 'UnityEngine.Rigidbody'
Comment
Answer by mrpmorris · Mar 10, 2018 at 06:46 PM
Your member is declared Rigidbody, and your GetComponent is setting it to a Rigidbody2D