Quantcast
Channel: Latest Questions by Grievemourne
Viewing all articles
Browse latest Browse all 51

What's stopping 'WaitForSeconds' from working?

$
0
0
I have the script with the coroutine: float maxDuration = 0.5f; public IEnumerator slowDown = null; float countdown = 0; public IEnumerator SlowTime(float scale, float dur){ if(dur > maxDuration){ dur = maxDuration; } if(dur < 0){ dur = 0.001f; } countdown = 0; Time.timeScale = scale; Debug.LogWarning("Scale: " + Time.timeScale + " - Duration: " + dur); yield return new WaitForSeconds(dur * Time.timeScale); Time.timeScale = 1; } and the script setting it ( where The final "Slow" function is probably the most relevant.): bool meleeDeflectionEnabled; bool projectileDeflectionEnabled; bool spellDeflectionEnabled; GameObject player = null; States playerState; GameObject enemy = null; public Vector3 deflectDirection; float distance = 1.5f; GameObject instancePrefab; float timeScale = 0.1f; float slowDuration = 0.5f; TimeControl timeControl; void Start(){ instancePrefab = Resources.Load("DeflectionTarget",typeof(GameObject)) as GameObject; player = transform.parent.gameObject; //deflectDirection = player.GetComponent().direction; playerState = player.GetComponent(); timeControl = GameObject.FindGameObjectWithTag("Vital").GetComponent(); } //This part is going to be called immediately, and only once, when something enters. I'm going to have to apply this script through script because of that... //since I can't .enabled = false the OnTriggerEnter part, only updates, which aren't in use. void OnTriggerEnter(Collider attack){ //if player is deflecting and if collider is attack, CheckAttack(attack); } void CheckAttack(Collider attack){ if(attack.tag == "Attack"){ if( attack.GetComponent() != null){ AttackTypes attackType = attack.GetComponent().attackType; if( attackType == AttackTypes.Melee){ enemy = attack.transform.parent.gameObject; Deflection(attack.transform, deflectDirection); } } } } void Deflection(Transform attack, Vector3 deflectDir){ //What does deflection mean? It means the the opponent is pushed towards a target location, and facing a certain direction. Slow(); Vector3 deflectPosition = (deflectDirection * distance) + player.transform.position; // Instantiate(instancePrefab, deflectPosition, Quaternion.identity); //Target location Have them both face it, and move toward it. //should I maybe handle the movement in the enemy AI? yeah. //where should the AI get the position data from? From the deflection volume? Sure. //enemy.transform.position enemy.GetComponent().deflectionPosition = deflectPosition; enemy.GetComponent().deflectedTime = enemy.GetComponent().defaultDeflectTime; //The attack is also displayed as nullified for the player. //stop damage of all attacks in those frames. //Get distance between attacker and target point, and have set the velocity so it happens over a set amount of seconds. //Rotate a set amount per second. Decided the the difference in degrees. //Get damage data and reduce the damage. //attack playerState.deflecting = false; Destroy(this); } void Slow(){ //Check if stopping coroutine is necessary if( timeControl.slowDown != null){ StopCoroutine(timeControl.slowDown); } //Set corouting data timeControl.slowDown = timeControl.SlowTime(timeScale, slowDuration); //start the coroutine StartCoroutine(timeControl.slowDown); //Set buffers. timeScale *= 2; slowDuration *= 0.6f; } I'm extremely confused as to what's happening since I get feedback that the script has been entered, but slowdown doesn't always happen in a similar script - but this one in particular only slows down, and doesn't recover, as if the " yield return new WaitForSeconds(dur * Time.timeScale);" line either never starts or never resolves.

Viewing all articles
Browse latest Browse all 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>