0

I've just started using Unity and started following tutorials online. (Flappy Bird). Nevertheless, I have a problem since my game action does not react to any kind of changes in code. Particularly, I've crib some parts of the code that should allow user to move bird object in upward direction when left click is pressed on the mouse, but it does not work. Bird just falls to the ground. It is also worth mentioning that this is not my code and several other people are following the same tutorial and everything works for them.

using UnityEngine;
using System.Collections;

public class Bird : MonoBehaviour 
{
    public float upForce = 200f;                  //Upward force of the "flap".
    private bool isDead = false;            //Has the player collided with a wall?

    private Animator anim;                  //Reference to the Animator component.
    private Rigidbody2D rb2d;               //Holds a reference to the Rigidbody2D component of the bird.

    void Start()
    {
        //Get reference to the Animator component attached to this GameObject.
        anim = GetComponent<Animator> ();
        //Get and store a reference to the Rigidbody2D attached to this GameObject.
        rb2d = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        //Don't allow control if the bird has died.
        if (isDead == false) 
        {
            //Look for input to trigger a "flap".
            if (Input.GetMouseButtonDown(0)) 
            {
                //...tell the animator about it and then...
                anim.SetTrigger("Flap");
                //...zero out the birds current y velocity before...
                rb2d.velocity = Vector2.zero;
                //  new Vector2(rb2d.velocity.x, 0);
                //..giving the bird some upward force.
                rb2d.AddForce(new Vector2(0, upForce));
            }
        }
    }

This is how I placed my script.

enter image description here

I've never used Unity before, maybe I have to change some settings ? Have in mind that we we're all following the same steps and it only does not work for me. I also set that the IDE I'm working with is my primary one.

1 Answer 1

1

I might be tired, but where do you give upForce a value? And is your script attached to a gameobject?

Sign up to request clarification or add additional context in comments.

2 Comments

Script is attached and this code does not show up, but the upForce value is 200f actually. I will edit now
Heh, it seems as it wasn't attached properly : ( It works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.