【发布时间】:2014-06-19 04:07:09
【问题描述】:
这是我不断收到空引用异常的脚本,但我不知道该怎么办?我在哪里分配什么?
using UnityEngine;
using System.Collections;
public class CurrencyManagment : MonoBehaviour {
public int Coins;
public CreditPlayer CreditPlayerScript;
void Start ()
{
CreditPlayerScript = GetComponent<CreditPlayer>();
}
void Awake()
{
CreditPlayerScript = GetComponent<CreditPlayer>();
}
void Update ()
{
Coins = CreditPlayerScript.CoinsTempContainer;
}
}
【问题讨论】:
-
你确定你确实有一个
CreditPlayer组件附加到使用CurrencyManagement的对象上吗? -
@Will 我是否有一个名为 credit player 的脚本,如启动函数中所述 CreditPlayerScript = GetComponent
();那条线指定了它吗?? -
不,该行检索已附加到对象的组件。
-
@wiz3kid 那么我需要做什么我有点困惑抱歉??
标签: c# unity3d game-engine