获取怪物
激活{随机激活}
获取怪物
激活{随机激活}
Targetmanager:刷东西用的
public GameObject[ ] monster;
public GameObject activateMonster=null;
private void ActivateMonster(){
int index = Random.Range(0,monsters.Length);
activateMonster=monsters[index];
activateMonster.SetActive(true);
activateMonster.GetComponent<BoxCollider>().enabled=true;
}
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TargetManager : MonoBehaviour { public GameObject[] monsters; public GameObject activeMonster = null; private void Start() { foreach(GameObject monster in monsters) { monster.GetComponent().enabled = false; monster.SetActive(false); } ActivateMonster(); } private void ActivateMonster() { int index = Random.Range(0,monsters.Length); activeMonster = monsters[index]; activeMonster.SetActive(true); activeMonster.GetComponent().enabled = true; } }
//随机生成怪物,用索引生成
前8个课程都是搭建场景的,未写代码
給Target添加一個腳本
把void start和voidUpdate刪掉
public GameObject[]mosters;
public GameObject activateMonster = null;
把四種怪物都拖進腳本
ptivate void Start(){
foreach(GameObject monster in monsters)
{
monster.SetActivate(false);
monster.GetComponent<BoxCollider>.enabled = false;
}
ActivateMonster();
}
private void ActivateMonster()
{
int index = Range(0,monsters.Lenght);
activateMonster = monster[index];
activate.SetActive(true);
activate.GetCompoment<BoxCollider>().enabled = true;
}
游戏物体.SetActive(true);
游戏物体.GetComponent<组件>().enabled=true;