小编Tim*_*meh的帖子

Unity无法找到其他GameObject的脚本

我从另一个GameObject的脚本中获取变量时遇到问题..我之前使用过这种类型的引用,我知道它是如何工作的,但由于某种原因,它说它无法找到我所指的脚本.

引用其他代码的代码(如果CanHearPlayer()开头的语句):

using UnityEngine;
using System.Collections;

public class EnemySight : MonoBehaviour {

public GameObject Player;
public float fieldOfViewDegrees = 30;
public float visibilityDistance = 50;
public bool SeeingPlayer;
public float deathDistance;
public float hearDistance;

void Update(){
    SeeingPlayer = CanSeePlayer();
    float Distance = Vector3.Distance(transform.position, Player.transform.position);

    if ((SeeingPlayer == true)) {
        transform.LookAt(Player.transform.position);

        if (Distance < deathDistance){
            Debug.Log("You died");
            //Game over sequence starts here
        }
    }

    if (CanHearPlayer () == true) {
        Debug.Log ("I can hear you.");
    }
}

protected bool CanSeePlayer()
{ …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

6
推荐指数
1
解决办法
1602
查看次数

标签 统计

c# ×1

unity-game-engine ×1