private void OnTriggerEnter(Collider other) { StopCoroutine("Bounce"); if (targetList.Count - 1 < extraTarget) { if (other.gameObject.tag == "Enemy" && !targetList.Exists(o => o == other.gameObject)) { Destroy(gameObject.GetComponent <SphereCollider>()); targetList.Add(other.gameObject); LightningChain lightning = Instantiate(this.lightning); if (lastTarget != null) { lightning.SetChain(lastTarget.transform, targetList[targetList.Count - 1].transform); } else { GameObject deadPoint = new GameObject("DeadPoint"); deadPoint.transform.position = lastTargetPosition; lightning.SetChain(deadPoint.transform, targetList[targetList.Count - 1].transform); } lastTarget = targetList[targetList.Count - 1]; lastTargetPosition = lastTarget.transform.position; transform.position = other.gameObject.transform.position; Destroy(lightning.gameObject, 0.5f); targetList[targetList.Count - 1].GetComponent <Enemy>().TakeDamage(damage); } } StartCoroutine("Bounce"); }
public Skill CreateSkill(Player player) { List <Skill> playerSkills = player.ListOfSkills; Skill known = CheckContent(playerSkills); if (known == null) { Blizzard s1 = new Blizzard(); LightningChain s2 = new LightningChain(); EarthShield s3 = new EarthShield(); List <Skill> tmp = new List <Skill>(); if (s1.MinimumLevel <= player.Level) { tmp.Add(s1); } if (s2.MinimumLevel <= player.Level) { tmp.Add(s2); } if (s3.MinimumLevel <= player.Level) { tmp.Add(s3); } if (tmp.Count == 0) { return(null); } return(tmp[Index.RNG(0, tmp.Count)]); } else if (known.decoratedSkill == null) { BlizzardDecorator s1 = new BlizzardDecorator(known); LightningChainDecorator s2 = new LightningChainDecorator(known); EarthShieldDecorator s3 = new EarthShieldDecorator(known); List <Skill> tmp = new List <Skill>(); if (s1.MinimumLevel <= player.Level) { tmp.Add(s1); } if (s2.MinimumLevel <= player.Level) { tmp.Add(s2); } if (s3.MinimumLevel <= player.Level) { tmp.Add(s3); } if (tmp.Count == 0) { return(null); } return(tmp[Index.RNG(0, tmp.Count)]); } else { return(null); } }
public void SetBouncer(float _damage, int _extraTarget, float _bounceRange, LightningChain _lightning, GameObject _target) { damage = _damage; extraTarget = _extraTarget; bounceRange = _bounceRange * 3.35f; lightning = _lightning; targetList.Add(_target); lastTarget = _target; lastTargetPosition = _target.transform.position; StartCoroutine("Bounce"); }
void ElectricBomb() { if (LC == null) { LC = new LightningChain(); } Vector2 dir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position; LC.playerPos = transform.position; LC.aimPos = (Vector2)transform.position + Vector2.ClampMagnitude(dir, 4); LC.MakeChain(); }
LightningChain getLightningChain() { if (m_lightningList.Count > 0) { LightningChain lc = m_lightningList[0]; m_lightningList.RemoveAt(0); lc.gameObject.SetActive(true); return(lc); } Transform trans = Instantiate(m_lightningPrefab, transform.position, Quaternion.identity, transform) as Transform; // 生成闪电实例 return(trans.GetComponent <LightningChain>()); }
public override void Attack() { if (attackTimer >= attackRate) { attackTimer = 0; LightningChain lightning = Instantiate(this.lightning); lightning.SetChain(firePositon.transform, enemyList[0].transform); Destroy(lightning.gameObject, 0.5f); GameObject bouncer = new GameObject("Empty"); bouncer.transform.position = enemyList[0].transform.position; bouncer.AddComponent <LightningBouncer>(); bouncer.GetComponent <LightningBouncer>().SetBouncer(damage, extraTarget, bounceRange, this.lightning, enemyList[0]); enemyList[0].GetComponent <Enemy>().TakeDamage(damage); } }
// Start is called before the first frame update void Start() { m_audioSource = this.GetComponent <AudioSource>(); m_patternName = this.transform.Find("PatternName"); m_patternTips = this.transform.Find("PatternTips"); m_leftLightning = this.transform.Find("LeftLightning").GetComponent <LightningChain>(); m_rightLightning = this.transform.Find("RightLightning").GetComponent <LightningChain>(); // 暂时隐藏提示 // m_patternTips.gameObject.SetActive(false); // 获取闪电位置 Vector3 pos = Camera.main.WorldToScreenPoint(m_patternName.position); Vector3 startPos = Camera.main.ScreenToWorldPoint(new Vector3(0, pos.y, pos.z)); Vector3 endPos = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, pos.y, pos.z)); float width = m_patternName.GetComponent <RectTransform>().rect.width; Vector3 leftPos = Camera.main.ScreenToWorldPoint(new Vector3(pos.x - width / 2, pos.y, pos.z)); Vector3 rightPos = Camera.main.ScreenToWorldPoint(new Vector3(pos.x + width / 2, pos.y, pos.z)); // 更新闪电链位置 m_leftLightning.UpdatePosList(startPos, leftPos); m_rightLightning.UpdatePosList(rightPos, endPos); }
void createLightningList(List <Vector3[]> posList) { // 更新闪电链对象 List <LightningChain> lcList = new List <LightningChain>(); foreach (Vector3[] pos in posList) { LightningChain lc = getLightningChain(); lc.UpdatePosList(pos[0], pos[1]); lcList.Insert(0, lc); } // 隐藏已有对象 foreach (LightningChain lc in m_lightningList) { lc.gameObject.SetActive(false); } // 更新m_lightningList foreach (LightningChain lc in lcList) { m_lightningList.Insert(0, lc); } }
// Update is called once per frame void Update() { if (PlayerControl.playerState == PlayerState.dead) { return; } time += Time.deltaTime; while (waveEvents.Count > 0 && time >= waveEvents[0].time) { WaveEvent e = waveEvents[0]; waveEvents.RemoveAt(0); switch (e.eventType) { case WaveEventType.seed: GameObject seedObject = Instantiate(prototypeSeed); seedObject.transform.position = e.position; break; case WaveEventType.towerAttack: audioThunder.transform.position = GetTowerPosition(e.tower); audioThunder.Play(); Vector3 direction = PlayerControl.playerPosition - GetTowerPosition(e.tower); RaycastHit hitInfo; Debug.DrawRay(GetTowerPosition(e.tower), direction); if (Physics.Raycast(GetTowerPosition(e.tower), direction, out hitInfo, 200f, towerRaycastMask.value)) { PlayerControl player = hitInfo.collider.gameObject.GetComponent <PlayerControl>(); Vector3 start = GetTowerPosition(e.tower); Vector3 end = hitInfo.point; if (player != null) { end += Vector3.down * 0.6f; player.Zapped(); } else { } overlayFlash.Go(0.2f); GameObject lightningChainObject = Instantiate(protoLightningChain); LightningChain chain = lightningChainObject.GetComponent <LightningChain>(); chain.MakeChain(start, end, 1f); } break; case WaveEventType.towerWarmup: GameObject lightningChainObjectW = Instantiate(protoLightningChain); LightningChain chainW = lightningChainObjectW.GetComponent <LightningChain>(); chainW.MakeChain(GetTowerPosition(e.tower) - Vector3.up * 3f, GetTowerPosition(e.tower) + Vector3.up * 15f, 10f); audioCharge.transform.position = GetTowerPosition(e.tower); audioCharge.Play(); break; case WaveEventType.gemDrop: GameObject gem = Instantiate(protoGem); gem.transform.position = e.position; break; } return; } }