private void Update() { // If the target exists... if (target != null) { // Move towards the target. agent.destination = target.transform.position; // Occasionally attempt to deal damage towards the target. float timePassed = ts.GetTimePassed(); timerBetweenAttacks -= timePassed; while (timerBetweenAttacks <= 0f) { timerBetweenAttacks += timeBetweenAttacks; float distance = Vector3.Distance(transform.position, target.transform.position); // If the enemy is close enough to the target to deal damage... if (distance < damageDistance) { // Damage the target. target.Damage(damage, Health.Type.Impact, true); // Play sound. soundArray.PlayRandomSound(); } } } }
public override void PointerLocationAbility(Vector3 location) { // Calculate the lightning's start and end points. Vector3 start, end; Vector3 additionalY = new Vector3(0f, lightningHeight, 0f); start = location + additionalY; end = location; //Debug.Log("Lightning StartObject/EndObject: " + compLightning.StartObject + ", " + compLightning.EndObject); // Interface with the third-party lightning script to create the lightning itself. compLightning.StartPosition = start; compLightning.EndPosition = end; compLightning.Trigger(); // Play a lightning sound. compSoundArray.PlayRandomSound(); // Instantiate the particles and area of effect object. Instantiate(lightningBlast, end, Quaternion.identity); Instantiate(areaOfEffect, end, Quaternion.identity); }