2017-01-20 1 views
0

저는 Unity를 사용하기 시작했고 온라인 튜토리얼을 시작했습니다. (Flappy Bird). 그럼에도 불구하고 게임 동작이 코드의 변경에 반응하지 않기 때문에 문제가 발생합니다. 특히 마우스 왼쪽 버튼을 누를 때 새 객체를 위쪽 방향으로 움직일 수 있어야하는 코드의 일부분은 침대에 있지만 작동하지 않습니다. 새가 땅에 떨어집니다. 이것은 또한 내 코드가 아니며 여러 다른 사람들이 동일한 자습서를 따르고 있으며 모든 것이 그 (것)들을 위해 작동한다는 것을 언급 할 가치가 있습니다.유니티 (2D)는 스크립트의 코드 변경에 반응하지 않습니다.

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)); 
      } 
     } 
    } 

이것은 내 스크립트를 배치 한 방법입니다.

enter image description here

나는 몇 가지 설정을 변경하기 전에 유니티를 어쩌면 내가 한 사용한 적이? 우리는 모두 동일한 단계를 따르고 있으며 단지 나를 위해 작동하지 않는다는 것을 명심하십시오. 또한 제가 작업하고있는 IDE가 기본 IDE라고 설정했습니다.

답변

1

피곤할 수도 있지만, 어디에서 값을 포기 하시겠습니까? 그리고 당신의 스크립트는 게임 객체에 붙어 있습니까?

+0

스크립트가 첨부되어 있으며이 코드는 표시되지 않지만 upForce 값은 실제로 200f입니다. 나는 지금 편집 할 것이다 – Seinfeld

+1

Heh, 그것은 올바르게 붙어 있지 않았던 것처럼 보인다 : (그것은 지금 작동한다. – Seinfeld

관련 문제