Синтаксис:
Используется csharp
using UnityEngine;
using UnityEngine.UI;
public class TankController : MonoBehaviour
{
[Header("Башня танка:")]
[SerializeField] private Transform tower;
[SerializeField] private float towerRotationSpeed;
Quaternion TowerRotation()
{
Vector3 mouse = Input.mousePosition;
mouse.z = Camera.main.transform.position.z;
Vector3 direction = Camera.main.ScreenToWorldPoint(mouse) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
return Quaternion.AngleAxis(angle, Vector3.forward);
}
void Update()
{
tower.rotation = Quaternion.Lerp(tower.rotation, TowerRotation(), towerRotationSpeed * Time.deltaTime);
}
}
using UnityEngine.UI;
public class TankController : MonoBehaviour
{
[Header("Башня танка:")]
[SerializeField] private Transform tower;
[SerializeField] private float towerRotationSpeed;
Quaternion TowerRotation()
{
Vector3 mouse = Input.mousePosition;
mouse.z = Camera.main.transform.position.z;
Vector3 direction = Camera.main.ScreenToWorldPoint(mouse) - transform.position;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
return Quaternion.AngleAxis(angle, Vector3.forward);
}
void Update()
{
tower.rotation = Quaternion.Lerp(tower.rotation, TowerRotation(), towerRotationSpeed * Time.deltaTime);
}
}