- Home /
How can bool work in rewinding timescale?
I need to make my bool statement work on rewind time (if my bool was true 5sec ago and then false then Im rewind timeScale back and my bool still false. How can it be done?Very need this please help on this one
And here is the code, main thing is where "moveRight" is set and there are time.velocity
using UnityEngine;
using System.Collections;
using Chronos;
public class Scientist : BaseBehaviour {
public float moveSpeed;
public bool moveRight;
public Transform sightStart, sightEnd;
public Transform flipStart, flipEnd;
public bool spotted = false;
public bool flip = false;
public GameObject arrow;
public LayerMask detectionLayers;
public Transform wallCheck;
public float wallCheckRadius;
public LayerMask whatIsWall;
private bool hittingWall;
public Transform edgeCheck;
public float edgeCheckRadius;
private bool notAtEdge;
public float timer = 3f; //Чтобы изменить время остановки нужно изменить кроме этого значения еще значение ниже, того же timer
public float smoothTime = 1f;
private float yVelocity = 0.0f;
Animator anim;
private Rigidbody2D rb2d;
void Start () {
rb2d = gameObject.GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
void Update () {
anim.SetFloat ("Speed", Mathf.Abs(rb2d.velocity.x));
Raycasting ();
Behaviours ();
hittingWall = Physics2D.OverlapCircle (wallCheck.position, wallCheckRadius, whatIsWall);
notAtEdge = Physics2D.OverlapCircle (edgeCheck.position, edgeCheckRadius, whatIsWall);
}
void FixedUpdate ()
{
if (hittingWall || !notAtEdge) {
if (timer > 0) {
timer -= Time.deltaTime;
return;
}
moveRight = !moveRight;
timer = 3f;
}
if (moveRight)
{
transform.localScale = new Vector3 (0.75f, 0.75f, 1f);
//rb2d.velocity = new Vector2(moveSpeed, rb2d.velocity.y);
if (time.timeScale > 0)
{
time.rigidbody2D.velocity = new Vector2 (moveSpeed, time.rigidbody2D.velocity.y);
}
} else {
transform.localScale = new Vector3 (-0.75f, 0.75f, 1f);
//rb2d.velocity = new Vector2(-moveSpeed, rb2d.velocity.y);
if (time.timeScale > 0)
{
time.rigidbody2D.velocity = new Vector2 (-moveSpeed, time.rigidbody2D.velocity.y);
}
}
Physics2D.IgnoreLayerCollision (16,16); //Даёт возможность не сталкиваться врагам
}
void Raycasting()
{
Debug.DrawLine (sightStart.position, sightEnd.position, Color.green);
spotted = Physics2D.Linecast (sightStart.position, sightEnd.position, detectionLayers);
Debug.DrawLine (flipStart.position, flipEnd.position, Color.red);
flip = Physics2D.Linecast (flipStart.position, flipEnd.position, detectionLayers);
}
void Behaviours()
{
if (spotted == true) {
arrow.SetActive (true);
moveSpeed = Mathf.SmoothDamp(moveSpeed,4.5f,ref yVelocity,smoothTime);
} else {
arrow.SetActive (false);
moveSpeed = Mathf.SmoothDamp(moveSpeed,2.5f,ref yVelocity, smoothTime);
}
if (flip == true && moveSpeed > 2.5f)
{
moveRight = !moveRight;
moveSpeed = 2.5f;
}
}
}
Answer by Ginxx009 · Jan 04, 2018 at 08:08 AM
I Guess You can do it something like this mate.
float timer = 5f;
bool pause = true;
public void Update(){
timer -= Time.DeltaTime;
if(timer <= 0f){
pause = false;
resetThis();
}
}
void ResetThis(){
pause = true;
timer = 5f;
}
I'm so sorry, i was tring to update my question for you :) And ins$$anonymous$$d it just delete it and create another! Okay so this boolean "moveRight" must be rewind exact like it would be in rewinding time in real life Do you think thats possible with that you send?
Hahaha >.< sorry also for answering quickly. I'll edit my answer
Well the code i share is basically resetting the set bool to what its original state. So basically if you think of it maybe it will work because you just need to rewind(going back to its original state) right?
And yeah, Im using Chronos I think it very similar with what we have in unity standart
Oh the timecontrol asset . hmm do you have that asset already?
Yes, sure I bought it and used the instruction in the asset I think it can be on their web too
Your answer
![](https://koobas.hobune.stream/wayback/20220612145810im_/https://answers.unity.com/themes/thub/images/avi.jpg)