public override void InstantiateProjectile(GameObject ProjectilePrefab, VictimController VictimToAttack, Transform TowerTransform, float Damage, float PoisonStrength, float SlowTo) { if (VictimToAttack == null) return; List<VictimController> VictimsToAttack = new List<VictimController>(); for (int i = 0; i < SubProjectilesCount; i++) { VictimController SubVictim = VictimsMainController.instance.GetClosestVictim((Vector2)VictimToAttack.transform.position, VictimsToAttack); if (SubVictim != null) { VictimsToAttack.Add(SubVictim); } else { break; } } foreach (VictimController vToAttack in VictimsToAttack) { GameObject Projectile = (GameObject)Instantiate (SubProjectilePrefab); Projectile.transform.SetParent (vToAttack.gameObject.transform); Projectile.transform.localPosition = Vector3.zero; ProjectileController _ProjectileController = Projectile.GetComponent<ProjectileController> (); _ProjectileController.VictimToAttack = vToAttack; _ProjectileController.PoisonStrength = PoisonStrength; _ProjectileController.SlowStrength = SlowTo; _ProjectileController.Damage = Damage; } }
public virtual void InstantiateProjectile(GameObject ProjectilePrefab, VictimController VictimToAttack, Transform TowerTransform, float Damage, float PoisonStrength, float SlowTo) { if (VictimToAttack == null) return; GameObject Projectile = (GameObject)Instantiate (ProjectilePrefab); Projectile.transform.SetParent (MapParentHandle.instance.gameObject.transform); Projectile.transform.position = TowerTransform.position; ProjectileController _ProjectileController = Projectile.GetComponent<ProjectileController> (); _ProjectileController.VictimToAttack = VictimToAttack; _ProjectileController.Damage = Damage; _ProjectileController.PoisonStrength = PoisonStrength; _ProjectileController.SlowStrength = SlowTo; Projectile.transform.localRotation = Quaternion.AngleAxis ( Mathf.Rad2Deg * Mathf.Atan2(VictimToAttack.transform.position.y - Projectile.transform.position.y, VictimToAttack.transform.position.x - Projectile.transform.position.x), Vector3.forward); foreach (ParticleSystem PS in Projectile.GetComponentsInChildren<ParticleSystem>(true)) { // to prevent trail when set start position PS.gameObject.SetActive(true); } }
void GameMenu() { noiseManager.enabled = false; // Create the victim. victimController = GameObject.Instantiate(victimPrefab).GetComponent <VictimController>(); victimController.GetComponent <Renderer>().enabled = false; }
void AI () { if (CanAttack) { VictimToAttack = FindVictim(); if (VictimToAttack != null) { Attack (); } } }
public override void InstantiateProjectile(GameObject ProjectilePrefab, VictimController VictimToAttack, Transform TowerTransform, float Damage, float PoisonStrength, float SlowTo) { if (VictimToAttack == null) return; GameObject Projectile = (GameObject)Instantiate (ProjectilePrefab); Projectile.transform.SetParent (VictimToAttack.gameObject.transform); Projectile.transform.localPosition = Vector3.zero; ProjectileController _ProjectileController = Projectile.GetComponent<ProjectileController> (); _ProjectileController.VictimToAttack = VictimToAttack; _ProjectileController.PoisonStrength = PoisonStrength; _ProjectileController.SlowStrength = SlowTo; _ProjectileController.Damage = Damage; }
public override void InstantiateProjectile(GameObject ProjectilePrefab, VictimController VictimToAttack, Transform TowerTransform, float Damage, float PoisonStrength, float SlowTo) { if (VictimToAttack == null) return; List<VictimController> VictimsToAttack = new List<VictimController>(); for (int i = 0; i < SubProjectilesCount; i++) { VictimController SubVictim = VictimsMainController.instance.GetClosestVictim((Vector2)VictimToAttack.transform.position, VictimsToAttack); if (SubVictim != null) { VictimsToAttack.Add(SubVictim); } else { break; } } foreach (VictimController vToAttack in VictimsToAttack) { GameObject Projectile = (GameObject)Instantiate (SubProjectilePrefab); Projectile.transform.SetParent (MapParentHandle.instance.gameObject.transform); Projectile.transform.position = TowerTransform.position; ProjectileController _ProjectileController = Projectile.GetComponent<ProjectileController> (); _ProjectileController.VictimToAttack = vToAttack; _ProjectileController.Damage = Damage; _ProjectileController.PoisonStrength = PoisonStrength; _ProjectileController.SlowStrength = SlowTo; Projectile.transform.localRotation = Quaternion.AngleAxis ( Mathf.Rad2Deg * Mathf.Atan2 (vToAttack.transform.position.y - Projectile.transform.position.y, vToAttack.transform.position.x - Projectile.transform.position.x), Vector3.forward); foreach (ParticleSystem PS in Projectile.GetComponentsInChildren<ParticleSystem>(true)) { // to prevent trail when set start position PS.gameObject.SetActive (true); } } }
// Update is called once per frame protected virtual void Update () { if (VictimToAttack == null) { VictimToAttack = VictimsMainController.instance.GetClosestVictim(transform.position); if (VictimToAttack == null) { InstantiateBlastEffect(); Destroy (gameObject); return; } } //rotation transform.localRotation = Quaternion.RotateTowards ( transform.localRotation, Quaternion.AngleAxis (Mathf.Rad2Deg * Mathf.Atan2 (VictimToAttack.transform.position.y - transform.position.y, VictimToAttack.transform.position.x - transform.position.x), Vector3.forward), RotateSpeed * Time.deltaTime ); //self rotation if (RotatingProjectile) { ProjectileImage.transform.Rotate (new Vector3(0.0f, 0.0f, RotatingProjectileRate * Time.deltaTime)); } // move transform.position += transform.right * MoveSpeed; // animation if (AnimationPlay) { if (AnimTimer > 0.0f) { AnimTimer -= Time.deltaTime; } else { AnimationIdx++; if (AnimationIdx >= AnimationSprites.Sprites.Length) { AnimationIdx = AnimationSprites.Sprites.Length - 1; AnimationPlay = false; AnimTimer = AnimInterval; HitVictimAfterAnimation (); AnimationPlay = true; AnimationIdx = 0; } ProjectileImage.sprite = AnimationSprites.Sprites [AnimationIdx]; AnimTimer = AnimInterval; } } }
// Update is called once per frame void Update () { AI (); // animation if (AnimationPlay) { if (AnimTimer > 0.0f) { AnimTimer -= Time.deltaTime; } else { AnimationIdx++; if (AnimationIdx >= AttackAnimation.Length) { AnimationIdx = AttackAnimation.Length - 1; AnimationPlay = false; ReverseAnimationPlay = true; if (InstantiateProjectileAfterAnimation) { if (VictimToAttack == null) { VictimToAttack = FindVictim(); } InstantiateProjectile(VictimToAttack); } } TowerImage.sprite = AttackAnimation [AnimationIdx]; AnimTimer = AnimInterval; } } else if (ReverseAnimationPlay) { if (AnimTimer > 0.0f) { AnimTimer -= Time.deltaTime; } else { AnimationIdx--; if (AnimationIdx <= 0) { AnimationIdx = 0; //AnimationPlay = true; ReverseAnimationPlay = false; TowerImage.sprite = IdleSprite; } else { TowerImage.sprite = AttackAnimation [AnimationIdx]; } AnimTimer = AnimInterval; } } //Attack cooldown if (!CanAttack) { if (AttackIntervalTimer > 0.0f) { AttackIntervalTimer -= Time.deltaTime; } else { CanAttack = true; } } }
protected virtual void InstantiateProjectile(VictimController VictimToAttack) { //ProjectilePrefab.GetComponent<ProjectileController> ().InstantiateProjectile (ProjectilePrefab, VictimToAttack, transform, Damage, PoisonStrength, SlowTo); ProjectilePrefab.GetComponent<ProjectileController> ().InstantiateProjectile (ProjectilePrefab, VictimToAttack, transform, Damage, Damage, SlowTo); }
public void Attack() { FlipToVictim (VictimToAttack.transform.position.x); CanAttack = false; AttackIntervalTimer = AttackInterval; AnimationPlay = true; if (!InstantiateProjectileAfterAnimation) { if (VictimToAttack == null) { VictimToAttack = FindVictim(); } InstantiateProjectile(VictimToAttack); } }