小编use*_*518的帖子

由于其保护级别,方法无法访问

我使用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);
    }

}
Run Code Online (Sandbox Code Playgroud)

脚本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;
    } …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

0
推荐指数
1
解决办法
1万
查看次数

"方法必须具有返回类型"错误

 public StudentClass(char level, int number, Teacher educator, int maxStudents)
    {
        this.level = level;
        this.number = number;
        this.educator = educator;
        this.numStudents = 0;
        this.students = new Student[maxStudents];

    }
    public StudentClass(char level, int number)
    {
        this.level = level;
        this.number = number;
        this.numStudent = 0;
        this.students = new Student[STANDART];
    }
Run Code Online (Sandbox Code Playgroud)

它给我一个错误的单词 - StudentClass请帮助我....谢谢你

c#

-4
推荐指数
1
解决办法
1932
查看次数

标签 统计

c# ×2

unity-game-engine ×1