【问题标题】:Unity (2D) does not react to code changes in scriptUnity (2D) 不会对脚本中的代码更改做出反应
【发布时间】:2017-01-21 06:34:59
【问题描述】:

我刚刚开始使用 Unity 并开始在线学习教程。 (飞扬的小鸟)。然而,我有一个问题,因为我的游戏动作不会对代码中的任何类型的更改做出反应。特别是,我已经编写了一些代码部分,这些部分应该允许用户在按下鼠标左键时向上移动鸟类对象,但它不起作用。鸟只是倒在地上。还值得一提的是,这不是我的代码,其他几个人都在遵循相同的教程,一切都对他们有用。

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

这就是我放置脚本的方式。

我以前从未使用过 Unity,也许我需要更改一些设置?请记住,我们都遵循相同的步骤,但这对我不起作用。我还设置了我正在使用的 IDE 是我的主要 IDE。

【问题讨论】:

    标签: c# unity5


    【解决方案1】:

    我可能累了,但你在哪里放弃强制值?您的脚本是否附加到游戏对象?

    【讨论】:

    • 脚本已附加,此代码未显示,但 upForce 值实际上是 200f。我现在要编辑
    • 嘿,好像没有正确连接:(现在可以了。
    猜你喜欢
    • 2012-08-05
    • 1970-01-01
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    相关资源
    最近更新 更多