public TentacleAttack GetTentacle() { if (tentacles.Count > 0) { for (int i = 0; i < tentacles.Count; i++) { if (!tentacles[i].gameObject.activeInHierarchy) { return(tentacles[i]); } } } if (notEnoughTentaclesInPool) { TentacleAttack t = Instantiate(pooledTentacle).GetComponent <TentacleAttack>(); t.gameObject.SetActive(false); //bullet pool and manager must be passed because it cannot be set in prefab t.setBulletPool(bulletPool); t.bossManager = base.bossManager; tentacles.Add(t); return(t); } return(null); }
public void SpawnTentacle(Vector2 target) { TentacleAttack tentacle = GetTentacle(); tentacle.transform.position = target; tentacle.gameObject.SetActive(true); }
public override void TStart() { base.TStart(); kraken = this.transform.parent.GetComponent <Kraken>(); prefab = Resources.Load("Prefabs/Enemies/Kraken") as GameObject; tentacleAtk = GetComponent <TentacleAttack>(); initialHealth = stats.health; }
void Update() { if (targetPlayer == false) { StartCoroutine(TargetPlayer()); } if (RecalcRot) { randomAng = new Vector3(Random.Range(-360, 360), Random.Range(-360, 360), Random.Range(-360, 360)); randomRotation = Quaternion.Euler(randomAng); RecalcRot = false; } Vector3 myPos = gameObject.transform.position; RaycastHit[] coneHits = physics.ConeCastAll(myPos, radius, transform.forward, depth, angle); if (target != null) { locked = true; } else if (target == null) { locked = !true; } if (locked) { if (Started != true) { StartCoroutine(WaitForUnlock()); } TentacleAttack attacker = null; float closestDist = Mathf.Infinity; // figure out which one is the closest tentacle for (int i = 0; i < tentacles.Length; i++) { if (tentacles[i] != null) { currentTip = tentacles[i].transform.GetChild(tentacles[i].transform.childCount - 1); TentacleAttack potentialAttacker = currentTip.GetComponent <TentacleAttack>(); if (potentialAttacker == false) { potentialAttacker = currentTip.gameObject.AddComponent <TentacleAttack>(); potentialAttacker.gameObject.AddComponent <ParticleSeek>(); } float myDist = (target.transform.position - currentTip.transform.position).magnitude; potentialAttacker.dist = myDist; if (myDist < closestDist) { attacker = potentialAttacker; closestDist = myDist; } } } // give orders to attack if (attacker != null) { attacker.MyTurnToAttack = true; closestTip = attacker.transform; } // look at my target gameObject.transform.LookAt(target.transform.position); } if (!locked) { Quaternion currentRot = transform.rotation; float step = speed * Time.deltaTime; transform.rotation = Quaternion.RotateTowards(transform.rotation, randomRotation, step); //Checks if the rotation locks itself and recalcs if the previous frames rotation == the current frames if (currentRot == lastRot) { RecalcRot = true; } lastRot = currentRot; //resets the rotation to look towards if it reaches its targeted rotation if (transform.rotation == randomRotation) { RecalcRot = true; } if (coneHits.Length > 0) { for (int i = 0; i < coneHits.Length; i++) { if (coneHits[i].collider == myColl || coneHits[i].collider.tag == "Tentacle" || coneHits[i].collider.tag == "Wall" || coneHits[i].collider.tag == "Obstacle") { continue; } target = coneHits[i].collider.gameObject; } } } }