Question by
ProductQualityZ · Jan 02, 2020 at 02:17 AM ·
animationtimewaittime.timescale
Animation Won't Play Before My Time Freeze.
I'm trying to install a time freeze animation but I need the animation to play before the freeze but I can't seem to do it. I may just be really dumb but if you know the answer, please help me (Yes, I did try changing the Update Mode to Unscaled time. It doesn't work nicely though).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 1f;
public Rigidbody2D rb;
Vector2 movement;
public Animator animator;
public bool freeze = false;
void Start()
{
animator.SetBool("Freeze", freeze);
StartCoroutine(Test());
}
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
if (Input.GetMouseButtonDown(1))
{
animateFreeze(true, 0, 5);
}
else if (Input.GetMouseButtonUp(1))
{
animateFreeze(false, 1, 3);
}
}
void FixedUpdate()
{
rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
}
public void freezeOrUnFreeze(bool determine)
{
freeze = determine;
animator.SetBool("Freeze", determine);
}
public void animateFreeze(bool determineAgain, float timeDetermine, int seconds)
{
freezeOrUnFreeze(determineAgain);
StartCoroutine(Wait(seconds));
Time.timeScale = timeDetermine;
}
IEnumerator Wait(int SecondsToWaitFor)
{
Debug.Log("Started Wait at timestamp : " + Time.time);
yield return new WaitForSeconds(SecondsToWaitFor);
Debug.Log("Finished Wait at timestamp : " + Time.time);
}
IEnumerator Test()
{
Debug.Log("Started Coroutine at timestamp : " + Time.time);
yield return new WaitForSeconds(3);
Debug.Log("Finished Coroutine at timestamp : " + Time.time);
}
}
Comment