using UnityEngine;
using System.Collections;
public class SquareController : MonoBehaviour
{
public float rotationAmount = 90.0f;
private bool isRotating = false;
void Update()
{
if (Input.GetMouseButtonDown(0) && !isRotating)
{
isRotating = true;
RotateCube();
}
}
void RotateCube()
{
float targetAngle = transform.eulerAngles.z + rotationAmount;
Quaternion targetRotation = Quaternion.Euler(0, 0, targetAngle);
StartCoroutine(RotateCoroutine(targetRotation));
}
System.Collections.IEnumerator RotateCoroutine(Quaternion targetRotation)
{
float duration = 0.5f;
Quaternion startRotation = transform.rotation;
float time = 0.0f;
while (time < duration)
{
transform.rotation = Quaternion.Lerp(startRotation, targetRotation, time / duration);
time += Time.deltaTime;
yield return null;
}
transform.rotation = targetRotation;
isRotating = false;
}
}
using UnityEngine;
using System.Collections;
public class SquareController : MonoBehaviour
{
public float rotationAmount = 90.0f;
private bool isRotating = false;
void Update()
{
if (Input.GetMouseButtonDown(0) && !isRotating)
{
isRotating = true;
RotateCube();
}
}
void RotateCube()
{
float targetAngle = transform.eulerAngles.z + rotationAmount;
Quaternion targetRotation = Quaternion.Euler(0, 0, targetAngle);
StartCoroutine(RotateCoroutine(targetRotation));
}
System.Collections.IEnumerator RotateCoroutine(Quaternion targetRotation)
{
float duration = 0.5f;
Quaternion startRotation = transform.rotation;
float time = 0.0f;
while (time < duration)
{
transform.rotation = Quaternion.Lerp(startRotation, targetRotation, time / duration);
time += Time.deltaTime;
yield return null;
}
transform.rotation = targetRotation;
isRotating = false;
}
}
using UnityEngine;
public class PortalScript : MonoBehaviour
{
Rigidbody2D rb;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Portal")
{
rb.gravityScale *= -1;
}
if (other.gameObject.tag == "GravitySwitch")
{
rb.gravityScale = 1;
}
}
}
using UnityEngine;
public class CubeController : MonoBehaviour
{
public float rotationAmount = 90.0f;
public KeyCode rotateKey = KeyCode.Space; // Или любую другую клавишу, которую вы хотите использовать
private bool isRotating = false;
void Update()
{
if (Input.GetKeyDown(rotateKey) && !isRotating)
{
isRotating = true;
RotateCube();
}
}
void RotateCube()
{
float targetAngle = transform.eulerAngles.z + rotationAmount;
Quaternion targetRotation = Quaternion.Euler(0, 0, targetAngle);
StartCoroutine(RotateCoroutine(targetRotation));
}
System.Collections.IEnumerator RotateCoroutine(Quaternion targetRotation)
{
float duration = 0.5f; // Продолжительность анимации в секундах
Quaternion startRotation = transform.rotation;
float time = 0.0f;
while (time < duration)
{
transform.rotation = Quaternion.Lerp(startRotation, targetRotation, time / duration);
time += Time.deltaTime;
yield return null;
}
transform.rotation = targetRotation;
isRotating = false;
}
}