private void towerAttack() { if (MainCore.Instance().particList.Count > 0 && !MainCore.Instance().particList[0].activeInHierarchy) { MainCore.Instance().particList[0].transform.SetParent(this.transform); MainCore.Instance().particList[0].transform.localPosition = new Vector3(0, 1.5f, 0); MainCore.Instance().particList[0].SetActive(true); MainCore.Instance().particList.RemoveAt(0); } else { GameObject par = GameObject.Instantiate(particPrefab); par.transform.SetParent(this.transform); par.transform.localPosition = new Vector3(0, 2f, 0); } for (int i = MainCore.Instance().monList.Count - 1; i >= 0; i--) { if (Vector3.Distance(MainCore.Instance().monList[i].gameObject.transform.position, this.transform.position) <= atkRange) { MainCore.Instance().monList[i].getAttack(atk); } } curMon = null; }
void OnEnable() { //GameObject objPrefab = GameObject.Instantiate((GameObject)Resources.Load("shibing")); //objPrefab.transform.SetParent(transform.parent); //objPrefab.transform.localPosition = new Vector3 (0.0f,0.0f,0.0f); Monster3D _monster3D = (Monster3D)PoolManager.getInstance().getGameObject("Monster3D"); _monster3D.transform.SetParent(transform.parent); _monster3D.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); _monster3D.init(null); }
// Update is called once per frame void Update() { for (int i = MainCore.Instance().monList.Count - 1; i >= 0; i--) { if (MainCore.Instance().monList[i] != null) { Monster3D mon = MainCore.Instance().monList[i]; if (Vector3.Distance(this.gameObject.transform.position, mon.monPrefab.transform.position) < atkRange) { if (atkMonList.IndexOf(mon) == -1) { atkMonList.Add(mon); //Debug.Log(i + "攻击" ); } } else { if (atkMonList.IndexOf(mon) >= 0) { atkMonList.Remove(mon); //Debug.Log(i + "移除" ); } } } } cdInit += Time.deltaTime; if (atkMonList.Count > 0) { if (atkMonList[0].isDeath) { atkMonList[0] = null; atkMonList.RemoveAt(0); } else { if (curMon == null && cdInit >= atkCd) { Debug.Log("attack!"); curMon = atkMonList[0]; towerAttack(); cdInit = 0; } } } }
public GameObject monCreat(GameObject prefab, int x, int z, Transform parent) { GameObject obj = GameObject.Instantiate(prefab); obj.transform.SetParent(parent); obj.transform.localScale = Vector3.one; obj.transform.localPosition = new Vector3(-0 + x * 1.5f, 1f, 0 - z * 1.5f); Monster3D mon = obj.AddComponent <Monster3D>(); mon.isMove = false; mon.speed = 0.008f; mon.monPrefab = obj; mon.Hp = 20; mon.hashX = spawnIndexX; mon.hashY = spawnIndexZ; MainCore.Instance().monList.Add(mon); return(obj); }
//怪物移动 private void monMove() { if (MainCore.Instance().monList.Count > 0) { for (int i = MainCore.Instance().monList.Count - 1; i >= 0; i--) { if (MainCore.Instance().monList[i].Hp > 0 && MainCore.Instance().monList[i].isMove == false) { Monster3D mon = MainCore.Instance().monList[i]; mon.nextPos = pathList[mon.pathIndex]; mon.isMove = true; } if (MainCore.Instance().monList[i].isMove == true && MainCore.Instance().monList[i] != null) { Monster3D mon = MainCore.Instance().monList[i]; mon.monPrefab.transform.localPosition = Vector3.MoveTowards(mon.monPrefab.transform.localPosition, mon.nextPos, mon.speed); if (Vector3.Distance(mon.monPrefab.transform.localPosition, mon.nextPos) < 0.001f) { if (mon.pathIndex >= pathList.Count - 1 && mon.speed <= 0.25) { mon.pathIndex = 0; mon.speed = mon.speed * 2; if (topSpeed < mon.speed) { isFrush = true; topSpeed = mon.speed; } } else { mon.pathIndex++; } mon.isMove = false; } } } } }
// Start is called before the first frame update void Start() { mon = obj.GetComponent <Monster3D>(); slid = this.GetComponent <Slider>(); slid.maxValue = mon.Hp; }