/// <summary> /// Update the word word word text underneat the progress/cd slider. /// Corrects for active / inactive word (color tag) /// </summary> /// <param name="timeHeld"></param> void UpdateWordText(float timeHeld) { StringBuilder builder = new StringBuilder(); builder.Append($"{shout[0].textWord} "); ShoutData.ShoutWord current = default; for (int i = 1; i < shout.Size; i++) { current = shout[i]; bool valid = timeHeld >= current.castTime; //change the color via the rich text tags. builder.Append($"<color=#{(valid? activeHexCol : inactiveHexCol)}>{current.textWord}</color> "); } wordsText.text = builder.ToString(); }
/// <summary> /// Apply the effects of the shout to objects in the scene. /// </summary> void DoShoutEffects(float timeHeld) { //figure out the strength of the shout. int words = 0; //default 0 for (int i = 1; i < shout.Size; i++) { if (timeHeld < shout[i].castTime) { break; } words = i; } //get all colliders. Collider[] hits = Physics.OverlapBox(transform.position + transform.TransformVector(boxOffset), boxHalfSize, transform.rotation, int.MaxValue); Vector3 origin = transform.position; anim.SetTrigger(shoutTrigger); ShoutData.ShoutWord finalShout = shout[words]; float strength = finalShout.strength; foreach (var hit in hits) { var rb = hit.GetComponent <Rigidbody>(); if (rb) { var dir = hit.transform.position - origin; dir.Normalize(); //dir.y = Mathf.Abs(dir.y); //never go straight down. thinking... rb.AddForce(dir * strength, ForceMode.Impulse); } } //test adding knockback to the player. playerController?.Launch(transform.forward * -strength * knockbackIntensity); //set the cooldown. remainingCooldown = (cooldown = finalShout.cooldown); }