我有一个塔的预制件,它具有一些基本统计数据,例如损坏和射程的公共变量.这些统计信息会被检查器中的内容覆盖,即使值是0,也会显示代码中定义的数字.
例如,如果我在预制件上将其设置为0,在代码中将其在Start函数上设置为5,则实例化时它将显示为5,但仅造成0损坏.即使我试图用代码覆盖它,它也只会造成预制件中定义的损坏程度.
我尝试将变量设为私有,但随后无法像这样引用敌人的值
Tower_1 t1Dmg = t1Ref.GetComponent<Tower_1>();
Tower_2 t2Dmg = t2Ref.GetComponent<Tower_2>();
Tower_3 t3Dmg = t3Ref.GetComponent<Tower_3>();
if(other.transform.tag == "Bullet")
{
Debug.Log("tower1Hitme");
health -= t1Dmg.t1damage; // Minus tower 1's current damage from our health per collision with "Bullet"
}
if (other.transform.tag == "Rocket")
{
health -= t2Dmg.rocketdamage; // Minus tower 2's current damage from our health per collision with "Rocket"
}
if (other.transform.tag == "Rocket")
{
health -= t2Dmg.miniRocketdamage; // Minus tower 1's current damage from our health per collision with "MiniRocket"
}
它可能是我最基本的东西,但是我似乎无法使它们的值与代码中设置的值相对应.
解决方法:
您需要HideInInspector:
用法示例:
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehavIoUr {
[HideInInspector]
public int p = 5;
}