Я использую Unity3D и C#, и у меня есть два сценария:метод недоступен из-за его уровня защиты
сценария 1:
using UnityEngine;
using System.Collections;
public class PlayerAttack : MonoBehaviour {
public GameObject target;
// Update is called once per frame
void Update() {
if(Input.GetKeyUp(KeyCode.F))
{
Attack();
}
}
void Attack() {
EnemyHealth eh = (EnemyHealth)target.GetComponent("EnemyHealth");
eh.HealthRulse(-10);
}
}
Сценарий 2:
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int curHealth = 100;
public int maxHealth = 100;
public float healthBarLeangth;
// Use this for initialization
void Start() {
healthBarLeangth = Screen.width/2;
}
// Update is called once per frame
void Update() {
HealthRulse(0);
}
void OnGUI() {
GUI.Box(new Rect(10,40,Screen.width/2/(maxHealth/curHealth),20),curHealth + "/" + maxHealth);
}
void HealthRulse(int adj){
if (curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
curHealth += adj;
healthBarLeangth = (Screen.width/2) * (curHealth/(float)maxHealth);
}
}
Функция «HeathRulse()», определенная в «сценарии 2» и вызываемая в «сценарии 1» GetComponent, выдает ошибку-
«Метод недоступен из-за его уровня защиты»
Мне нужна помощь с этим ...
возможно дубликат [недоступен из-за его уровня защиты] (http://stackoverflow.com/questions/ 6125077/недоступен по причине его уровня защиты) или любой из ста других подобных вопросов ... –