Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class smoothMovementAndRotate : MonoBehaviour
- {
- // 1с == 1 квадрат при швидкості 1.
- // 0.5 швидкість, 2с часу == 1 квадрат пропливає
- public float defSpeed = 1;
- public float speedRotate = 1;
- public float speedMove = 1;
- public float timeTurn = 2;
- private void Start()
- {
- Invoke("resetTurn", timeTurn);
- }
- private void Update()
- {
- if (Input.GetKeyDown(KeyCode.Q))
- setSpeedRotate(-defSpeed);
- if (Input.GetKeyDown(KeyCode.E))
- setSpeedRotate(defSpeed);
- transform.Translate(new Vector3(speedRotate, 0, -speedMove) * Time.deltaTime);
- }
- private void resetTurn()
- {
- speedRotate = 0;
- }
- private void setSpeedRotate(float speed)
- {
- speedRotate = speed > 0 ? Mathf.Abs(speed) : -Mathf.Abs(speed);
- Invoke("resetTurn", timeTurn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement