Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why I can't see how my player rewinds?

Discussion in 'Editor & General Support' started by Lex_212, Nov 18, 2020.

  1. Lex_212

    Lex_212

    Joined:
    Oct 3, 2020
    Posts:
    84
    Hi, in my game, you can rewind time, when I play the game on the editor, you can see the effect, but when I export it, it doesn't you, but it's still rewinding, I just want to now if this is a code error or if there is something wrong with my computer. This is my code.

    Point time:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class PointTime
    5. {
    6.     public Vector3 position;
    7.     public Quaternion rotation;
    8.  
    9.     public PointTime (Vector3 _position, Quaternion _rotation)
    10.     {
    11.         position = _position;
    12.         rotation = _rotation;
    13.     }
    14. }
    15.  
    TimeBod:
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class TimeBod : MonoBehaviour
    7. {
    8.     public bool isRewinding = false;
    9.  
    10.     public Health health;
    11.  
    12.     List<PointTime> pointsInTime;
    13.  
    14.     Rigidbody rb;
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.         pointsInTime = new List<PointTime>();
    20.         rb = GetComponent<Rigidbody>();
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.         if (Input.GetKeyDown(KeyCode.Mouse1))
    27.         {
    28.             StartRewind();
    29.         }
    30.         if (Input.GetKeyUp(KeyCode.Mouse1))
    31.         {
    32.             StopRewind();
    33.         }
    34.     }
    35.  
    36.     void FixedUpdate()
    37.     {
    38.         if (isRewinding)
    39.         {
    40.             Rewind();
    41.         }
    42.         else
    43.         {
    44.             Record();
    45.         }
    46.     }
    47.  
    48.     void Rewind()
    49.     {
    50.         if (pointsInTime.Count > 0)
    51.         {
    52.             PointTime pointTime = pointsInTime[0];
    53.             transform.position = pointTime.position;
    54.             transform.rotation = pointTime.rotation;
    55.             pointsInTime.RemoveAt(0);
    56.             health.RewindDamage(0.4f);
    57.         }
    58.         else
    59.         {
    60.             StopRewind();
    61.         }
    62.     }
    63.  
    64.     void Record()
    65.     {
    66.         pointsInTime.Insert(0, new PointTime(transform.position, transform.rotation));
    67.     }
    68.  
    69.     public void StartRewind()
    70.     {
    71.         isRewinding = true;
    72.         rb.isKinematic = true;
    73.     }
    74.  
    75.     public void StopRewind()
    76.     {
    77.         isRewinding = false;
    78.         rb.isKinematic = false;
    79.     }
    80. }
    81.