Max_Divizion f5561a9c31 Create speedometer
Продолжение разработки спидометра
2024-05-14 15:21:26 +03:00

41 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// NULLcode Studio © 2015
// null-code.ru
using UnityEngine;
using System.Collections;
public class Speedometer : MonoBehaviour {
public float _start; // начальное положение стрелки по оси Z
public float maxSpeed; // максимальная скорость на спидометре
public RectTransform arrow; // стрелка спидометра
public enum ProjectMode {Project3D = 0, Project2D = 1};
public ProjectMode projectMode = ProjectMode.Project3D;
public Transform target; // объект с которого берем скорость
public float velocity; // текущая реальная скорость объекта
private Rigidbody _3D;
private Rigidbody2D _2D;
private float speed;
void Start ()
{
arrow.localRotation = Quaternion.Euler(0, 0, _start);
if(projectMode == ProjectMode.Project3D) _3D = target.GetComponent<Rigidbody>();
else _2D = target.GetComponent<Rigidbody2D>();
}
void Update ()
{
if(projectMode == ProjectMode.Project3D) velocity = _3D.velocity.magnitude; else velocity = _2D.velocity.magnitude;
if(velocity > maxSpeed) velocity = maxSpeed;
speed = _start - velocity;
arrow.localRotation = Quaternion.Euler(0, 0, speed);
}
}