Unity (2D) 不响应脚本中的代码更改
Unity (2D) does not react to code changes in script
我刚开始使用 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 是我的主要对象。
我可能累了,但你在哪里放弃强制值?您的脚本是否已附加到游戏对象?
我刚开始使用 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 是我的主要对象。
我可能累了,但你在哪里放弃强制值?您的脚本是否已附加到游戏对象?