C# Unity(2D)不会对脚本中的代码更改做出反应
我刚刚开始使用Unity,并开始在线学习教程。(扇形鸟)。然而,我有一个问题,因为我的游戏动作不会对代码中的任何变化做出反应。特别是,我已经编写了代码的一些部分,当鼠标左键按下时,应该允许用户向上移动bird对象,但它不起作用。鸟刚落在地上。还值得一提的是,这不是我的代码,其他几个人也在遵循相同的教程,并且一切都适合他们C# Unity(2D)不会对脚本中的代码更改做出反应,c#,unity5,C#,Unity5,我刚刚开始使用Unity,并开始在线学习教程。(扇形鸟)。然而,我有一个问题,因为我的游戏动作不会对代码中的任何变化做出反应。特别是,我已经编写了代码的一些部分,当鼠标左键按下时,应该允许用户向上移动bird对象,但它不起作用。鸟刚落在地上。还值得一提的是,这不是我的代码,其他几个人也在遵循相同的教程,并且一切都适合他们 using UnityEngine; using System.Collections; public class Bird : MonoBehaviour { p
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));
}
}
}
使用UnityEngine;
使用系统集合;
公共类鸟类:单性行为
{
公共浮子向上力=200f;//翻板向上力。
private bool isDead=false;//玩家是否与墙相撞?
私有Animator anim;//对Animator组件的引用。
private rigiidbody2d rb2d;//保存对bird的rigiidbody2d组件的引用。
void Start()
{
//获取附加到此游戏对象的Animator组件的引用。
anim=GetComponent
我以前从未使用过Unity,也许我必须更改一些设置?请记住,我们都遵循相同的步骤,但这对我不起作用。我还设置了我正在使用的IDE是我的主要IDE。我可能很累,但你在哪里放弃强制值?你的脚本是否附加到游戏对象?脚本是attac这个代码并没有显示,但upForce的值实际上是200f。我现在就编辑它,它似乎没有正确连接:(它现在可以工作了。