亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將浮點數添加到另一個腳本中,C#統一

將浮點數添加到另一個腳本中,C#統一

C#
Cats萌萌 2021-04-30 09:10:21
我需要幫助,我正在嘗試將一個腳本中的浮點數添加到另一個腳本中,但是它不起作用。我是C#和編碼的新手,如果有人代碼修復了腳本并解釋了這是怎么回事,我將非常感激。這是我得到的錯誤。 “ NullReferenceException:對象引用未設置為對象的實例Resources.Die()(在Assets / Resources.cs:42處)Resources.Update()(在Assets / Resources.cs:22處)”這是我的腳本:1stusing System.Collections;using System.Collections.Generic;using UnityEngine;public class Resources : MonoBehaviour {    public float maxHealth = 5;    public float currentHealth;    public float ResourceCounter;    public Texture stoneIcon;    public Texture woodIcon;    void Start ()    {        currentHealth = maxHealth;        ResourceCounter = 0;    }    void Update ()    {        Die();    }    public void OnMouseOver()    {        if(Input.GetButtonDown("Fire1"))        {            Debug.Log("Loosing one health");            currentHealth = currentHealth - 1f;        }    }    public void Die()    {        if(currentHealth <= 0)        {            Destroy(gameObject);            Inventory inventory = GetComponent<Inventory>();            inventory.ResourceStone = inventory.ResourceStone + 1;        }    }}第二名using System.Collections;using System.Collections.Generic;using UnityEngine;public class Inventory : MonoBehaviour {    public float ResourceStone;    // Use this for initialization    void Start ()    {        ResourceStone = 0;}    // Update is called once per frame    void Update () {    }}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 153 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號