交换游戏对象时出错

时间:2014-05-20 10:52:43

标签: c# unity3d unityscript

我想只用宝石组件交换宝石,这是不可见的我尝试了片段打击,但我得到了nullexception错误:

NullReferenceException: Object reference not set to an instance of an object
board.SwapGem () (at Assets/Resources/Scripts/board.cs:81)
Gem.OnMouseDown () (at Assets/Resources/Scripts/Gem.cs:59)
UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

我做错了什么?

board.cs

public List<Gem> gems = new List<Gem>();
    public Gem LastGem;
    public Vector3 gem1start,gem2start,gem1end,gem2end;

    public Gem gem1,gem2; // gem to change i

    public Gem gemComponent;

    // Use this for initialization
    void Start () {
        gem1start=gem1.transform.position;
        gem1end = gemComponent.transform.position;
    }


    // Update is called once per frame
    void Update () {

                }
    }

    public void SwapGem()
    {
        gem2start = gem1start;
        gem2end = gem1end;
        gem1.transform.position = gem2start;
        gemComponent.transform.position = gem2end;

    }

gem.cs

public void OnMouseDown()
    {

        if (!GameObject.Find("board").GetComponent<board>().isSwapping) 
        {
              ToggleSelector ();
            GameObject.Find ("board").GetComponent<board> ().SwapGem ();
        }
    }

0 个答案:

没有答案