private void Shoot() { TargetFinding tf = new TargetFinding(); if (tf.FindATarget(out Vector2 direction, out GameObject obj, transform.position, Target, AttRange, "Enemy")) { GameObject thisProjectile = Instantiate(ThisPlantProjectile); thisProjectile.GetComponent <PlantProjectile>().Damage = Damage; thisProjectile.GetComponent <PlantProjectile>().MovementSpeed = ProjectileSpeed; thisProjectile.GetComponent <PlantProjectile>().AttRange = AttRange; thisProjectile.GetComponent <PlantProjectile>().Knockback = Knockback; thisProjectile.GetComponent <PlantProjectile>().target = obj; thisProjectile.GetComponent <PlantProjectile>().oldDirection = (Vector3)(direction.normalized * 1.1f); thisProjectile.GetComponent <PlantProjectile>().transform.position = transform.position; ChangeWaterSupply(-ProjectileCost); } }
public new void Fly() { if (first) { first = false; TargetFinding tf = new TargetFinding(); Vector2 direction = Vector2.zero; if (tf.FindSpecialTarget(ref direction, target, transform.position)) { Rigidbody.MovePosition(direction.normalized * MovementSpeed * Time.fixedDeltaTime * AttRange); } else { Destroy(gameObject); } } else if (lifeTime > 0) { Destroy(gameObject); } }
public void Fly() { if (lifeTime > 0) { if (cd >= targetCooldown) { TargetFinding tf = new TargetFinding(); Vector2 direction = oldDirection; if (tf.FindSpecialTarget(ref direction, target, transform.position)) { direction = direction.normalized * MovementSpeed * Time.fixedDeltaTime; oldDirection = direction; } cd = 0; } else { cd += Time.fixedDeltaTime; } Debug.DrawRay(transform.position, oldDirection, Color.cyan, 1); if (((Vector2)transform.position + oldDirection).magnitude < 10000) { Rigidbody.MovePosition((Vector2)transform.position + oldDirection); } else { Destroy(gameObject); } lifeTime -= Time.fixedDeltaTime; } else { Destroy(gameObject); } }
public virtual void Awake() { paused = false; commandManager = GetComponent <CommandManager>(); Targeting = GetComponent <TargetFinding>(); }