// Update is called once per frame void Update() { if(gameFM.gStatus == -1) { if(resume) //when you resume you have to give all properties back to each object, velocities and gravity { rigidbody.velocity = current.movement; rigidbody.angularVelocity = current.angular; rigidbody.useGravity = true; // cut everything AFTER index (because we're resuming at previous frame if(index +1 != stack.Count) stack.RemoveRange(index, stack.Count-index -1); } resume = false; // keep it false so we can know when it's our "first" pause update for later below, needed for logical comparissons index = -1; // we only need index when game is paused, at which point we set it to the size -1 (aka index of newest push onto stack) Vector3 p = rigidbody.position; Vector3 m = rigidbody.velocity; Vector3 a = rigidbody.angularVelocity; tSave inst = new tSave (m, p, a); stack.Add(inst); //here we save all data for each object for each stack } else { if(index == -1) index = stack.Count-1; if(!resume) current = new tSave(rigidbody.velocity, rigidbody.position, rigidbody.angularVelocity); // saves/initiatilizes current resume = true; //once more we use "resume" for a logical comparisson if(gameFM.gStatus == 0) { rigidbody.velocity = new Vector3(0,0,0); rigidbody.angularVelocity = new Vector3(0,0,0); rigidbody.useGravity = false; //zero out all objects to simulate a "pause" } else if(gameFM.gStatus == 1 && index != 0) { index--; //as long as we don't go negative in index we can iterate backwards current = (tSave)stack[index]; pUpdate(); } else if(index + 1 != stack.Count) { // as long as we don't exceed the range of the array we can iterate forwards index ++; current = (tSave)stack[index]; pUpdate(); } } }
SphereCollider sphere; // triger collider!!! #endregion Fields #region Methods // refreezes the state public void freeze() { pauseObject (); thirdState = 0; iteration = null; }
void Start() { sphere = gameObject.AddComponent<SphereCollider> (); sphere.radius = 1; sphere.isTrigger = true; //gameMan = GameObject.Find("gameManager"); localFM = (gameFM)gameMan.GetComponent (typeof(gameFM)); iteration = null; thirdState = 0; // doing nothing /init index = -1; //initialization resume = false; }
// Update is called once per frame void Update() { if (rigidbody.detectCollisions == false) Debug.Log ("FFUCKED"); if (localFM.getStatus() == 100) { rigidbody.velocity = new Vector3(0,0,0); rigidbody.angularVelocity = new Vector3(0,0,0); return; } /// 3rd dimension //Debug.Log ("state: " + gameFM.gStatus + " -- " + thirdState); if (localFM.getStatus() == 0 && thirdState == 1 && (iteration == null || iteration.movement == current.movement)) { // change to non 1d pause state if(iteration == null) // unit { rigidbody.useGravity = true; iteration = new tSave( new Vector3(0,0,0), new Vector3(0,0,0), new Vector3(0,0,0), new Quaternion(0,0,0,0)); startTime = Time.time; } else {// Vector3 m, Vector3 p, Vector3 a, Quaternion r float timeHolder = (Time.time - startTime) / 2; // change divider to change " duration of thaw" if(iteration.movement != current.movement) iteration.movement += timeHolder * current.movement; // no need for position if(iteration.angular != current.angular) iteration.angular += timeHolder * current.angular; // no need for rotation if(Time.time - startTime >= 2) // fail safefeee { iteration.movement = current.movement; iteration.angular = current.angular; } } } /// end of 3rd dimension if(localFM.getStatus() == -1) { if(resume) //when you resume you have to give all properties back to each object, velocities and gravity { iteration = null; // clears it for the next time we use rigidbody.velocity = current.movement; rigidbody.angularVelocity = current.angular; rigidbody.useGravity = true; // cut everything AFTER index (because we're resuming at previous frame if(index +1 != stack.Count) stack.RemoveRange(index, stack.Count-index); } resume = false; // keep it false so we can know when it's our "first" pause update for later below, needed for logical comparissons index = -1; // we only need index when game is paused, at which point we set it to the size -1 (aka index of newest push onto stack) tSave inst = new tSave (rigidbody.velocity, transform.position, rigidbody.angularVelocity, rigidbody.rotation); stack.Add(inst); //here we save all data for each object for each stack } else { if(index == -1) index = stack.Count-1; if(!resume) current = new tSave(rigidbody.velocity, transform.position, rigidbody.angularVelocity, rigidbody.rotation); // saves/initiatilizes current if(localFM.getStatus() == 0 && !resume) // now only called once at the start pauseObject(); else if(localFM.getStatus() == 0) {} // do nothing simply used for logic at this point else if(localFM.getStatus() == 1 && index != 0 && localFM.getDimension() == 1) { index--; //as long as we don't go negative in index we can iterate backwards current = (tSave)stack[index]; pUpdate(); } else if(localFM.getStatus() == 2 && index + 1 != stack.Count && localFM.getDimension() == 1) { // as long as we don't exceed the range of the array we can iterate forwards index ++; current = (tSave)stack[index]; pUpdate(); } else if(localFM.getDimension() == 1) { localFM.setStatus(100); } } }