// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.E)) { if (inst.IsEnoughEnergy(RocketEnergyCost) && _canUseRocket) { inst.ChangeEnergy(-RocketEnergyCost); Instantiate(RocketPrefab, MarkDecal.transform.position + new Vector3(0, 5, 0), Quaternion.Euler(0, 0, 90)); StartCoroutine(RocketCoolDown()); } } if (Input.GetKeyDown(KeyCode.Mouse0)) { AudioManager.instance.PlayMGSound(); } if (Input.GetKeyUp(KeyCode.Mouse0)) { AudioManager.instance.StopMGSound(); } if (Input.GetKey(KeyCode.Mouse0)) { Gun.transform.Rotate(new Vector3(0, 0, 1), gunRotSpeed, Space.Self); if (fireCountdown <= 0f) { Shoot(); if (fireRate >= 0) { fireCountdown = 1f / fireRate; } } fireCountdown -= Time.deltaTime; } partToRotate.transform.localPosition = new Vector3(0, partToRotate.transform.localPosition.y, 0); if (!partToRotate.GetComponent <TimeBody>().IsRewinding()) { var ray = cam.ScreenPointToRay(Input.mousePosition); var hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { hitPoint = hit.point; target = hit.point; MarkDecal.transform.position = target + target.normalized * .1f; MarkDecal.transform.rotation = Quaternion.LookRotation(-hit.normal); var dir = target - transform.position; var lookRot = Quaternion.LookRotation(dir); var rotation = Quaternion.Lerp(partToRotate.rotation, lookRot, Time.deltaTime * rotSpeed).eulerAngles; partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f); } } }
void Rewind() { if (pointsInTime.Count > 1) { PointInTime pointInTime = pointsInTime.First.Value; transform.position = pointInTime.position; transform.rotation = pointInTime.rotation; inst.ChangeHP(pointInTime.health - inst._currentHP); pointsInTime.RemoveFirst(); inst.ChangeEnergy(-RewindCost); } else { StopRewind(); } }