Очки за дрифт
This commit is contained in:
parent
dca0c8d0c1
commit
50ec58d9a8
8
Assets/Prefab/UI/Fonts.meta
Normal file
8
Assets/Prefab/UI/Fonts.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9719638f26e556f4fbe1f0c12718f710
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
4279
Assets/Prefab/UI/Fonts/LBNOutline.asset
Normal file
4279
Assets/Prefab/UI/Fonts/LBNOutline.asset
Normal file
File diff suppressed because one or more lines are too long
8
Assets/Prefab/UI/Fonts/LBNOutline.asset.meta
Normal file
8
Assets/Prefab/UI/Fonts/LBNOutline.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4991592a1585c3846afa91f8858d0d12
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed3d101d8fa2b3941a4531458ec57175
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
119
Assets/Scripts/UI/DriftScore.cs
Normal file
119
Assets/Scripts/UI/DriftScore.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class DriftScore : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Rigidbody playerRB;
|
||||
[SerializeField] private TMP_Text totalScoreText;
|
||||
[SerializeField] private TMP_Text currentScoreText;
|
||||
[SerializeField] private TMP_Text factorText;
|
||||
[SerializeField] private TMP_Text driftAngleText;
|
||||
|
||||
private float speed = 0;
|
||||
private float driftAngle = 0;
|
||||
private float driftFactor = 1;
|
||||
private float currentScore;
|
||||
private float totalScore;
|
||||
|
||||
private bool isDrifting = false;
|
||||
|
||||
[SerializeField] private float minimumSpeed = 5;
|
||||
[SerializeField] private float minimumAngle = 10;
|
||||
[SerializeField] private float driftingDelay = 0.2f;
|
||||
[SerializeField] private GameObject driftingObject;
|
||||
[SerializeField] private Color normalDriftColor;
|
||||
[SerializeField] private Color nearStopColor;
|
||||
[SerializeField] private Color driftEndedColor;
|
||||
|
||||
private IEnumerator stopDriftingCoroutine = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
driftingObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
ManagerDrift();
|
||||
ManageUI();
|
||||
}
|
||||
void ManagerDrift()
|
||||
{
|
||||
speed = playerRB.velocity.magnitude;
|
||||
driftAngle = Vector3.Angle(playerRB.transform.forward, (playerRB.velocity + playerRB.transform.forward).normalized);
|
||||
if (driftAngle > 120)
|
||||
{
|
||||
driftAngle = 0;
|
||||
}
|
||||
if (driftAngle >= minimumAngle && speed > minimumSpeed)
|
||||
{
|
||||
if (!isDrifting || stopDriftingCoroutine != null)
|
||||
{
|
||||
StartDrift();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isDrifting && stopDriftingCoroutine == null)
|
||||
{
|
||||
StopDrift();
|
||||
}
|
||||
}
|
||||
if (isDrifting)
|
||||
{
|
||||
currentScore += Time.deltaTime * driftAngle * driftFactor;
|
||||
driftFactor += Time.deltaTime;
|
||||
driftingObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
async void StartDrift()
|
||||
{
|
||||
if (!isDrifting)
|
||||
{
|
||||
await Task.Delay(Mathf.RoundToInt(1000 * driftingDelay));
|
||||
driftFactor = 1;
|
||||
}
|
||||
if (stopDriftingCoroutine != null)
|
||||
{
|
||||
StopCoroutine(stopDriftingCoroutine);
|
||||
stopDriftingCoroutine = null;
|
||||
}
|
||||
currentScoreText.color = normalDriftColor;
|
||||
isDrifting = true;
|
||||
|
||||
}
|
||||
void StopDrift()
|
||||
{
|
||||
stopDriftingCoroutine = StoppingDrift();
|
||||
StartCoroutine(stopDriftingCoroutine);
|
||||
|
||||
}
|
||||
private IEnumerator StoppingDrift()
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
currentScoreText.color = Color.yellow;
|
||||
|
||||
yield return new WaitForSeconds(driftingDelay * 4f);
|
||||
totalScore += currentScore;
|
||||
isDrifting = false;
|
||||
currentScoreText.color = Color.red;
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
currentScore = 0;
|
||||
driftingObject.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
void ManageUI()
|
||||
{
|
||||
totalScoreText.text = "Ðåêîðä: " + (totalScore).ToString("###,###,000");
|
||||
factorText.text = driftFactor.ToString("###,###,##0.0") + "X";
|
||||
currentScoreText.text = currentScore.ToString("###,###,000");
|
||||
driftAngleText.text = driftAngle.ToString("###,##0");
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/UI/DriftScore.cs.meta
Normal file
11
Assets/Scripts/UI/DriftScore.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb93655aa55fc7644b1844ee83011ba7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user