Unity3d 没有从 modevelop 获取代码

Unity3d does not get code from monodevelop

我的 Unity 项目有问题。该项目是构建一个简单的 PackMan 游戏,但游戏引擎似乎没有从 IDE 获取代码。我读过其他人也有同样的问题。这是代码:

using UnityEngine;
using System.Collections;

public class PacManMovement : MonoBehaviour {
    public float speed = 0.4f;  
    Vector2 destPoint = Vector2.zero;
    // Use this for initialization
    void Start () {
        destPoint = transform.position;
    }
    void    Update(){
    }
    //when using physincs better use FixedUpdate!!!
    void FixedUpdate(){
        //moving toward the destination
        Vector2 p = Vector2.MoveTowards (transform.position, destPoint, speed);
        rigidbody2D.MovePosition(p);

        if ((Vector2)transform.position == destPoint) {
            if (Input.GetKey (KeyCode.UpArrow) && valid (Vector2.up))
                destPoint = (Vector2)transform.position + Vector2.up;
            if (Input.GetKey (KeyCode.RightArrow) && valid (Vector2.right))
                destPoint = (Vector2)transform.position + Vector2.right;
            if (Input.GetKey (KeyCode.DownArrow) && valid (-Vector2.up))
                destPoint = (Vector2)transform.position - Vector2.up;
            if (Input.GetKey (KeyCode.LeftArrow) && valid (-Vector2.right))
                destPoint = (Vector2)transform.position - Vector2.right;
        }
    }

    bool valid (Vector2 dir){
        //cast line
        Vector2 pos = transform.position;
        RaycastHit2D hit = Physics2D.Linecast (pos + dir, pos);
        return(hit.collider == collider2D);
    }
}

我推荐这种方法:

  • 使用 Unity 创建 C# 脚本(Assets > Create > C# Script) .
  • 在 Unity 中,双击脚本名称以在您喜欢的编辑器(Mono Develop、Visual Studio 等)中打开它。
  • 编写脚本,并确保保存它。
  • 在 Unity 中检查脚本的预览窗格,它应该显示(部分)您新编写的代码。
  • 确保脚本作为组件附加到正确的游戏对象。

您可以从 Edit > Preferences -> External Script Editor 更改首选编辑器.