생활
C# if문 질문 있습니다.(유니티 관련)
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Rotation : MonoBehaviour{ public float duration = 1f; public float angle = 90f; bool isRotating = false; float remainingAngle; float remainingDuration; void Update() { if (Input.GetKeyDown(KeyCode.Space) && !isRotating) { isRotating = true; remainingAngle = angle; remainingDuration = duration; if (isRotating) { float anglePerFrame = remainingAngle / remainingDuration * Time.deltaTime; if (remainingAngle < anglePerFrame) { anglePerFrame = remainingAngle; isRotating = false; } transform.Rotate(Vector3.up * anglePerFrame); remainingAngle -= anglePerFrame; remainingDuration -= Time.deltaTime; } } }}위의 코드와 아래 코드의 실행 결과가 왜 다르게 나오는지 모르겠습니다.
using System.Collections;using System.Collections.Generic;using UnityEngine;public class Selection0 : MonoBehaviour{ public float angle = 90f; public float duration = 1f; private bool isRotating = false; float remainingAngle; float remainingDuration; void Update() { if (Input.GetKeyDown(KeyCode.Space) && !isRotating) { isRotating = true; remainingAngle = angle; remainingDuration = duration; } if (isRotating) { float anglePerFrame = remainingAngle /remainingDuration * Time.deltaTime; if (remainingAngle < anglePerFrame) { anglePerFrame = remainingAngle; isRotating = false; } transform.Rotate(Vector3.up * anglePerFrame); remainingAngle -= anglePerFrame; remainingDuration -= Time.deltaTime; } }}아직 답변이 없어요.