Create speedometer
Продолжение разработки спидометра
This commit is contained in:
8
Assets/Scripts/Dashboard.meta
Normal file
8
Assets/Scripts/Dashboard.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3effd0ac89e49c243bc676ca1f501c02
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Scripts/Dashboard/Speedometer.cs
Normal file
40
Assets/Scripts/Dashboard/Speedometer.cs
Normal file
@ -0,0 +1,40 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
12
Assets/Scripts/Dashboard/Speedometer.cs.meta
Normal file
12
Assets/Scripts/Dashboard/Speedometer.cs.meta
Normal file
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc8a35d8d11fc644b8a18fe03d40b99b
|
||||
timeCreated: 1442287611
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Menu.meta
Normal file
8
Assets/Scripts/Menu.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a67bd4d20c190c4890b424998584b25
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user