黑魂 207角色管理

发布时间 2023-07-20 18:55:18作者: dontpanic1703

新建一个ActorManager脚本代码。

在class下面写:

public BattleManager bm; 定义一个新的战斗管理

start改成:

void Awake()
{
  GameObject sensor = transform.Find("sensor").gameObject;
}

把这个脚本绑定在PlayerHandle里。

在GameObject下面加上:

bm = sensor.GetComponent<BattleManager>();
if (bm == null)
{
  bm = sensor.AddComponent<BattleManager>();
}

在BattleManager脚本里补上一个ActorManager变量和start函数。以及定义一个胶囊体,运行游戏后可以把start函数的代码套在sensor上

public ActorManager am;

private CapsuleCollider defCol;
void Start()
{
  defCol = GetComponent<CapsuleCollider>();
  defCol.center = Vector3.up*1.0f;
  defCol.height = 2.0f;
  defCol.radius = 0.25f;
  defCol.isTrigger = true;
}

在ActorManager里加上:

bm.am=this;

这样ActorManager和BattleManager就能互相识别检测。