// Update is called once per frame void Update() { age += Time.deltaTime; //update the age if (armTime <= 0.0f && !isActive) { Debug.Log("armTime is 0 or less!"); isActive = true; Debug.Log("trap armed!"); } //traps don't move so no changes in its position after placement //they need to count down to become active if (armTime > 0.0f) //if it's still counting down { armTime -= Time.deltaTime; //update arming countdown time Debug.Log("armTime = " + armTime); if (armTime <= 0.0f) //if it's done counting down, activate the trap { isActive = true; Debug.Log("trap armed!"); } } if (firingDupes) { if (duplicateTimer.TimeElapsedSecs() > duplicateDelay) { if (duplicatedTimes < duplicate) { FireEffect(); duplicateTimer.Restart(); duplicatedTimes++; if (duplicatedTimes >= duplicate) { usesLeft--; if (usesLeft <= 0) { Debug.Log("dupe trap expended"); Destroy(this.gameObject); } firingDupes = false; duplicatedTimes = 0; } } else { Debug.Log("trap duplicate power shouldn't reach here"); } } } if (attraction != 0.0f) { List <Enemy> inRange = Dial.GetAllEnemiesInZone(zone); foreach (Enemy e in inRange) { Vector2 attractionVector = rt.anchoredPosition - e.GetComponent <RectTransform>().anchoredPosition; Vector2 direction = attractionVector.normalized; float distFromTrap = attractionVector.magnitude; Steering s = e.GetComponent <Steering>(); float strength = s.maxAccel * 0.99f; //baseline maximum float percentOfMax = attraction / TEMP_MAX_ATTRACTION; //use attraction number to get how close to the max attraction you're at strength *= percentOfMax; //multiply to get acceleration Vector2 adjusted = direction * strength; //then apply that to the direction vector s.ExternalForceUpdate(this, adjusted); //and tell the AI to be pulled that way } } }