Reputation: 433
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.
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.
Upvotes: 0
Views: 150
Reputation: 97
I might be tired, but where do you give upForce a value? And is your script attached to a gameobject?
Upvotes: 1