first commit
This commit is contained in:
56
Assets/Scripts/Asrtronaut/AstronautAnimator.cs
Normal file
56
Assets/Scripts/Asrtronaut/AstronautAnimator.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AstronautAnimator : MonoBehaviour
|
||||
{
|
||||
private Animator _animator;
|
||||
private float _ratio = 1f;
|
||||
private float _massFactor = 1f;
|
||||
private bool _isJumping;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void SetRatio(float ratio)
|
||||
{
|
||||
_ratio = ratio;
|
||||
}
|
||||
|
||||
public void SetMass(float mass)
|
||||
{
|
||||
float clamped = Mathf.Clamp(mass, 30f, 100f);
|
||||
float t = Mathf.InverseLerp(30f, 100f, clamped);
|
||||
_massFactor = Mathf.Lerp(1.05f, 0.95f, t);
|
||||
}
|
||||
|
||||
public void SetWalking(bool isWalking)
|
||||
{
|
||||
_animator.SetBool("isWalking", isWalking);
|
||||
}
|
||||
|
||||
public void Jump()
|
||||
{
|
||||
_animator.SetTrigger("Jump");
|
||||
_isJumping = true;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
bool isGrounded = Physics.CheckSphere(transform.parent.position + Vector3.down * 0.5f, 0.3f);
|
||||
float animSpeed = (_ratio <= 0.2f)
|
||||
? 1.5f
|
||||
: Mathf.Clamp(1f / (_ratio * 1.5f), 0.15f, 3f);
|
||||
if (isGrounded)
|
||||
{
|
||||
_isJumping = false;
|
||||
_animator.speed = animSpeed * _massFactor;
|
||||
}
|
||||
else if (_isJumping)
|
||||
{
|
||||
_animator.speed = animSpeed * _massFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/AstronautAnimator.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/AstronautAnimator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a7b2628c1767c64f8b1c59620ac9153
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
204
Assets/Scripts/Asrtronaut/AstronautController.cs
Normal file
204
Assets/Scripts/Asrtronaut/AstronautController.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class AstronautController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float _moveSpeed = 3f;
|
||||
[SerializeField] private float _jumpForce = 10f;
|
||||
[SerializeField] private Planet _currentPlanet = Planet.Earth;
|
||||
[SerializeField] private AstronautAnimator _astronautAnimator;
|
||||
[SerializeField] private TextMeshProUGUI _planetText;
|
||||
[SerializeField] private TextMeshProUGUI _gravityText;
|
||||
public Planet CurrentPlanet => _currentPlanet;
|
||||
|
||||
public enum Planet
|
||||
{
|
||||
Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune, Sun
|
||||
}
|
||||
|
||||
private Rigidbody _rb;
|
||||
private bool _isGrounded;
|
||||
private bool _isJumping;
|
||||
private float _ratio = 1f;
|
||||
|
||||
float GetGravity(Planet planet)
|
||||
{
|
||||
switch (planet)
|
||||
{
|
||||
case Planet.Mercury: return 3.72f;
|
||||
case Planet.Venus: return 8.87f;
|
||||
case Planet.Earth: return 9.81f;
|
||||
case Planet.Moon: return 1.62f;
|
||||
case Planet.Mars: return 3.721f;
|
||||
case Planet.Jupiter: return 24.79f;
|
||||
case Planet.Saturn: return 10.44f;
|
||||
case Planet.Uranus: return 8.69f;
|
||||
case Planet.Neptune: return 11.15f;
|
||||
case Planet.Sun: return 274f;
|
||||
default: return 9.81f;
|
||||
}
|
||||
}
|
||||
|
||||
string GetPlanetNameUA(Planet planet)
|
||||
{
|
||||
switch (planet)
|
||||
{
|
||||
case Planet.Mercury: return "Меркурій";
|
||||
case Planet.Venus: return "Венера";
|
||||
case Planet.Earth: return "Земля";
|
||||
case Planet.Moon: return "Місяць";
|
||||
case Planet.Mars: return "Марс";
|
||||
case Planet.Jupiter: return "Юпітер";
|
||||
case Planet.Saturn: return "Сатурн";
|
||||
case Planet.Uranus: return "Уран";
|
||||
case Planet.Neptune: return "Нептун";
|
||||
case Planet.Sun: return "Сонце";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
float GetSpeedMultiplier()
|
||||
{
|
||||
if (_currentPlanet == Planet.Moon) return 1.5f;
|
||||
return Mathf.Clamp(1f / (_ratio * 1.5f), 0.15f, 3f);
|
||||
}
|
||||
|
||||
void ApplyGravity()
|
||||
{
|
||||
Physics.gravity = new Vector3(0, -GetGravity(_currentPlanet), 0);
|
||||
_ratio = GetGravity(_currentPlanet) / 9.81f;
|
||||
_astronautAnimator.SetRatio(_ratio);
|
||||
if (_planetText != null)
|
||||
_planetText.text = GetPlanetNameUA(_currentPlanet);
|
||||
}
|
||||
|
||||
IEnumerator ShowGravityText()
|
||||
{
|
||||
_gravityText.text = "Прискорення падіння: " + GetGravity(_currentPlanet).ToString("F2") + " м/с²";
|
||||
float t = 0f;
|
||||
while (t < 1f)
|
||||
{
|
||||
t += Time.deltaTime * 2f;
|
||||
_gravityText.alpha = t;
|
||||
yield return null;
|
||||
}
|
||||
yield return new WaitForSeconds(4f);
|
||||
t = 1f;
|
||||
while (t > 0f)
|
||||
{
|
||||
t -= Time.deltaTime * 2f;
|
||||
_gravityText.alpha = t;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
float GetClampedMass()
|
||||
{
|
||||
return Mathf.Clamp(_rb.mass, 30f, 100f);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody>();
|
||||
_rb.freezeRotation = true;
|
||||
if (_gravityText != null)
|
||||
_gravityText.alpha = 0f;
|
||||
ApplyGravity();
|
||||
_astronautAnimator.SetMass(GetClampedMass());
|
||||
}
|
||||
|
||||
public void RefreshMass()
|
||||
{
|
||||
_astronautAnimator.SetMass(GetClampedMass());
|
||||
}
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Ground"))
|
||||
{
|
||||
_isGrounded = true;
|
||||
_isJumping = false;
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionExit(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Ground"))
|
||||
{
|
||||
_isGrounded = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1)) { _currentPlanet = Planet.Mercury; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2)) { _currentPlanet = Planet.Venus; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha3)) { _currentPlanet = Planet.Earth; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha4)) { _currentPlanet = Planet.Moon; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha5)) { _currentPlanet = Planet.Mars; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha6)) { _currentPlanet = Planet.Jupiter; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha7)) { _currentPlanet = Planet.Saturn; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha8)) { _currentPlanet = Planet.Uranus; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha9)) { _currentPlanet = Planet.Neptune; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Alpha0)) { _currentPlanet = Planet.Sun; ApplyGravity(); }
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Keypad1)) { _currentPlanet = Planet.Mercury; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad2)) { _currentPlanet = Planet.Venus; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad3)) { _currentPlanet = Planet.Earth; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad4)) { _currentPlanet = Planet.Moon; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad5)) { _currentPlanet = Planet.Mars; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad6)) { _currentPlanet = Planet.Jupiter; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad7)) { _currentPlanet = Planet.Saturn; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad8)) { _currentPlanet = Planet.Uranus; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad9)) { _currentPlanet = Planet.Neptune; ApplyGravity(); }
|
||||
if (Input.GetKeyDown(KeyCode.Keypad0)) { _currentPlanet = Planet.Sun; ApplyGravity(); }
|
||||
|
||||
float currentSpeed = _moveSpeed * GetSpeedMultiplier();
|
||||
float h = Input.GetAxis("Horizontal");
|
||||
float v = Input.GetAxis("Vertical");
|
||||
bool isWalking = Mathf.Abs(h) > 0.1f || Mathf.Abs(v) > 0.1f;
|
||||
|
||||
if (!_isJumping)
|
||||
{
|
||||
Vector3 move = new Vector3(-h, 0, -v).normalized * currentSpeed;
|
||||
_rb.velocity = new Vector3(move.x, _rb.velocity.y, move.z);
|
||||
if (isWalking)
|
||||
transform.forward = new Vector3(-h, 0, -v).normalized;
|
||||
}
|
||||
|
||||
_astronautAnimator.SetWalking(isWalking && !_isJumping);
|
||||
|
||||
bool canJump = _currentPlanet == Planet.Sun ? true : (_isGrounded && !_isJumping);
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space) && canJump)
|
||||
{
|
||||
_isJumping = true;
|
||||
_astronautAnimator.Jump();
|
||||
StartCoroutine(JumpForceDelay());
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator JumpForceDelay()
|
||||
{
|
||||
float animSpeed = (_currentPlanet == Planet.Moon)
|
||||
? 1.5f
|
||||
: Mathf.Clamp(1f / (_ratio * 1.5f), 0.15f, 3f);
|
||||
float delay = 0.7f / animSpeed;
|
||||
yield return new WaitForSeconds(delay);
|
||||
_rb.velocity = new Vector3(_rb.velocity.x, 0, _rb.velocity.z);
|
||||
float clampedMass = GetClampedMass();
|
||||
float savedMass = _rb.mass;
|
||||
_rb.mass = 75f;
|
||||
_rb.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse);
|
||||
_rb.mass = savedMass;
|
||||
float bonus = Mathf.Lerp(1.5f, -1.5f, Mathf.InverseLerp(30f, 100f, clampedMass));
|
||||
_rb.AddForce(Vector3.up * bonus, ForceMode.VelocityChange);
|
||||
if (_gravityText != null)
|
||||
StartCoroutine(ShowGravityText());
|
||||
if (_currentPlanet == Planet.Sun)
|
||||
_isJumping = false;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/AstronautController.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/AstronautController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc8b6ef8dd6ffc64b95ee2cbea5060ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/Asrtronaut/CameraFollow.cs
Normal file
25
Assets/Scripts/Asrtronaut/CameraFollow.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform _target;
|
||||
[SerializeField] private float _smoothSpeed = 5f;
|
||||
|
||||
private float _offsetY;
|
||||
private float _minY;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_offsetY = transform.position.y - _target.position.y;
|
||||
_minY = transform.position.y;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
float targetY = Mathf.Max(_target.position.y + _offsetY, _minY);
|
||||
Vector3 newPos = new Vector3(transform.position.x, targetY, transform.position.z);
|
||||
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * _smoothSpeed);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/CameraFollow.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/CameraFollow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9969e7e7ef928ad4f91ef1baf675454d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
162
Assets/Scripts/Asrtronaut/CameraTransition.cs
Normal file
162
Assets/Scripts/Asrtronaut/CameraTransition.cs
Normal file
@@ -0,0 +1,162 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraTransition : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Camera _cinematicCamera;
|
||||
[SerializeField] private Camera _astronautCamera;
|
||||
[SerializeField] private Camera _secretCamera;
|
||||
[SerializeField] private Transform _endPoint;
|
||||
[SerializeField] private float _duration = 2f;
|
||||
[SerializeField] private GameObject _astronautCanvas;
|
||||
[SerializeField] private GameObject _planetCanvas;
|
||||
[SerializeField] private GameObject _secretCanvas;
|
||||
[SerializeField] private UnityEngine.UI.Button _secretButton;
|
||||
[SerializeField] private AstronautController _astronautController;
|
||||
[SerializeField] private GameObject _secretPlanet;
|
||||
[SerializeField] private GameObject _mainPlanet;
|
||||
|
||||
private Vector3 _startPos;
|
||||
private Quaternion _startRot;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_startPos = _cinematicCamera.transform.position;
|
||||
_startRot = _cinematicCamera.transform.rotation;
|
||||
|
||||
_cinematicCamera.gameObject.SetActive(true);
|
||||
_astronautCamera.gameObject.SetActive(false);
|
||||
_secretCamera.gameObject.SetActive(false);
|
||||
_astronautController.enabled = false;
|
||||
_astronautCanvas.SetActive(false);
|
||||
_secretCanvas.SetActive(false);
|
||||
_planetCanvas.SetActive(true);
|
||||
_secretButton.gameObject.SetActive(false);
|
||||
_secretPlanet.SetActive(false);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_astronautCanvas.activeSelf && Input.GetKeyDown(KeyCode.LeftControl))
|
||||
{
|
||||
_secretButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void StartTransition()
|
||||
{
|
||||
_planetCanvas.SetActive(false);
|
||||
StartCoroutine(FlyToAstronaut());
|
||||
}
|
||||
|
||||
public void ReturnToPlanets()
|
||||
{
|
||||
_astronautCanvas.SetActive(false);
|
||||
_astronautController.enabled = false;
|
||||
_astronautCamera.gameObject.SetActive(false);
|
||||
_cinematicCamera.gameObject.SetActive(true);
|
||||
StartCoroutine(FlyBack());
|
||||
}
|
||||
|
||||
public void GoToSecret()
|
||||
{
|
||||
_astronautCanvas.SetActive(false);
|
||||
_astronautController.enabled = false;
|
||||
_astronautCamera.gameObject.SetActive(false);
|
||||
_cinematicCamera.gameObject.SetActive(true);
|
||||
StartCoroutine(FlyToSecret());
|
||||
}
|
||||
|
||||
public void ReturnFromSecret()
|
||||
{
|
||||
_secretCanvas.SetActive(false);
|
||||
_secretCamera.gameObject.SetActive(false);
|
||||
_cinematicCamera.gameObject.SetActive(true);
|
||||
StartCoroutine(FlyFromSecret());
|
||||
}
|
||||
|
||||
IEnumerator FlyToAstronaut()
|
||||
{
|
||||
float t = 0f;
|
||||
Vector3 startPos = _cinematicCamera.transform.position;
|
||||
Quaternion startRot = _cinematicCamera.transform.rotation;
|
||||
|
||||
while (t < 1f)
|
||||
{
|
||||
t += Time.deltaTime / _duration;
|
||||
_cinematicCamera.transform.position = Vector3.Lerp(startPos, _endPoint.position, Mathf.SmoothStep(0f, 1f, t));
|
||||
_cinematicCamera.transform.rotation = Quaternion.Lerp(startRot, _endPoint.rotation, Mathf.SmoothStep(0f, 1f, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_cinematicCamera.gameObject.SetActive(false);
|
||||
_astronautCamera.gameObject.SetActive(true);
|
||||
_astronautCanvas.SetActive(true);
|
||||
_astronautController.enabled = true;
|
||||
}
|
||||
|
||||
IEnumerator FlyBack()
|
||||
{
|
||||
float t = 0f;
|
||||
Vector3 startPos = _cinematicCamera.transform.position;
|
||||
Quaternion startRot = _cinematicCamera.transform.rotation;
|
||||
|
||||
while (t < 1f)
|
||||
{
|
||||
t += Time.deltaTime / _duration;
|
||||
_cinematicCamera.transform.position = Vector3.Lerp(startPos, _startPos, Mathf.SmoothStep(0f, 1f, t));
|
||||
_cinematicCamera.transform.rotation = Quaternion.Lerp(startRot, _startRot, Mathf.SmoothStep(0f, 1f, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_planetCanvas.SetActive(true);
|
||||
}
|
||||
|
||||
IEnumerator FlyToSecret()
|
||||
{
|
||||
float t = 0f;
|
||||
Vector3 startPos = _cinematicCamera.transform.position;
|
||||
Quaternion startRot = _cinematicCamera.transform.rotation;
|
||||
Vector3 secretPos = _secretCamera.transform.position;
|
||||
Quaternion secretRot = _secretCamera.transform.rotation;
|
||||
|
||||
while (t < 1f)
|
||||
{
|
||||
t += Time.deltaTime / _duration;
|
||||
_cinematicCamera.transform.position = Vector3.Lerp(startPos, secretPos, Mathf.SmoothStep(0f, 1f, t));
|
||||
_cinematicCamera.transform.rotation = Quaternion.Lerp(startRot, secretRot, Mathf.SmoothStep(0f, 1f, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_cinematicCamera.gameObject.SetActive(false);
|
||||
_secretCamera.gameObject.SetActive(true);
|
||||
_secretCanvas.SetActive(true);
|
||||
_secretPlanet.SetActive(true);
|
||||
_mainPlanet.SetActive(false);
|
||||
}
|
||||
|
||||
IEnumerator FlyFromSecret()
|
||||
{
|
||||
float t = 0f;
|
||||
Vector3 startPos = _cinematicCamera.transform.position;
|
||||
Quaternion startRot = _cinematicCamera.transform.rotation;
|
||||
Vector3 targetPos = _astronautCamera.transform.position;
|
||||
Quaternion targetRot = _astronautCamera.transform.rotation;
|
||||
|
||||
while (t < 1f)
|
||||
{
|
||||
t += Time.deltaTime / _duration;
|
||||
_cinematicCamera.transform.position = Vector3.Lerp(startPos, targetPos, Mathf.SmoothStep(0f, 1f, t));
|
||||
_cinematicCamera.transform.rotation = Quaternion.Lerp(startRot, targetRot, Mathf.SmoothStep(0f, 1f, t));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
_cinematicCamera.gameObject.SetActive(false);
|
||||
_astronautCamera.gameObject.SetActive(true);
|
||||
_astronautController.enabled = true;
|
||||
_astronautCanvas.SetActive(true);
|
||||
_mainPlanet.SetActive(true);
|
||||
_secretPlanet.SetActive(false);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/CameraTransition.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/CameraTransition.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10bffe552295e6f458dec97634b9fcec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/Asrtronaut/PlanetDropdown.cs
Normal file
28
Assets/Scripts/Asrtronaut/PlanetDropdown.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class PlanetDropdown : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Dropdown _dropdown;
|
||||
[SerializeField] private PlanetWeight.PlanetName _planet;
|
||||
[SerializeField] private TextMeshProUGUI _planetNameText;
|
||||
|
||||
public TMP_Dropdown Dropdown => _dropdown;
|
||||
public int PlanetIndex => (int)_planet;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (_planetNameText != null)
|
||||
_planetNameText.text = _planet.ToString();
|
||||
|
||||
_dropdown.onValueChanged.AddListener(OnValueChanged);
|
||||
}
|
||||
|
||||
void OnValueChanged(int index)
|
||||
{
|
||||
if (_planetNameText != null)
|
||||
_planetNameText.text = _planet.ToString();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/PlanetDropdown.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/PlanetDropdown.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fd961003a4484e4695c1ed8bd9b4422
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Assets/Scripts/Asrtronaut/PlanetLighting.cs
Normal file
61
Assets/Scripts/Asrtronaut/PlanetLighting.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlanetLighting : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AstronautController _controller;
|
||||
private Light _light;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_light = GetComponent<Light>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
switch (_controller.CurrentPlanet)
|
||||
{
|
||||
case AstronautController.Planet.Mercury:
|
||||
_light.color = new Color(1f, 0.9f, 0.7f);
|
||||
_light.intensity = 1.8f;
|
||||
break;
|
||||
case AstronautController.Planet.Venus:
|
||||
_light.color = new Color(1f, 0.7f, 0.3f);
|
||||
_light.intensity = 1.4f;
|
||||
break;
|
||||
case AstronautController.Planet.Earth:
|
||||
_light.color = new Color(1f, 0.98f, 0.9f);
|
||||
_light.intensity = 1f;
|
||||
break;
|
||||
case AstronautController.Planet.Moon:
|
||||
_light.color = new Color(0.7f, 0.75f, 0.9f);
|
||||
_light.intensity = 0.6f;
|
||||
break;
|
||||
case AstronautController.Planet.Mars:
|
||||
_light.color = new Color(1f, 0.5f, 0.2f);
|
||||
_light.intensity = 0.8f;
|
||||
break;
|
||||
case AstronautController.Planet.Jupiter:
|
||||
_light.color = new Color(1f, 0.85f, 0.6f);
|
||||
_light.intensity = 0.4f;
|
||||
break;
|
||||
case AstronautController.Planet.Saturn:
|
||||
_light.color = new Color(0.9f, 0.8f, 0.5f);
|
||||
_light.intensity = 0.35f;
|
||||
break;
|
||||
case AstronautController.Planet.Uranus:
|
||||
_light.color = new Color(0.4f, 0.8f, 1f);
|
||||
_light.intensity = 0.2f;
|
||||
break;
|
||||
case AstronautController.Planet.Neptune:
|
||||
_light.color = new Color(0.2f, 0.4f, 1f);
|
||||
_light.intensity = 0.15f;
|
||||
break;
|
||||
case AstronautController.Planet.Sun:
|
||||
_light.color = new Color(1f, 1f, 0.8f);
|
||||
_light.intensity = 5f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/PlanetLighting.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/PlanetLighting.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a564b0668864d74db51987ffa73db47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Scripts/Asrtronaut/PlanetWeight.cs
Normal file
89
Assets/Scripts/Asrtronaut/PlanetWeight.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlanetWeight : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI _resultText;
|
||||
[SerializeField] private Button _checkButton;
|
||||
[SerializeField] private Rigidbody _astronautRb;
|
||||
|
||||
public enum PlanetName
|
||||
{
|
||||
Ìåðêóð³é, Âåíåðà, Çåìëÿ, ̳ñÿöü, Ìàðñ, Þï³òåð, Ñàòóðí, Óðàí, Íåïòóí, Ñîíöå
|
||||
}
|
||||
|
||||
float[] _gravities = { 3.7f, 8.87f, 9.81f, 1.62f, 3.71f, 24.79f, 10.44f, 8.69f, 11.15f, 274f };
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
RebuildDropdowns();
|
||||
}
|
||||
|
||||
void RebuildDropdowns()
|
||||
{
|
||||
float mass = _astronautRb != null ? _astronautRb.mass : 75f;
|
||||
PlanetDropdown[] planetDropdowns = FindObjectsOfType<PlanetDropdown>();
|
||||
foreach (var pd in planetDropdowns)
|
||||
{
|
||||
pd.Dropdown.ClearOptions();
|
||||
pd.Dropdown.options.Add(new TMP_Dropdown.OptionData("Îáðàòè"));
|
||||
foreach (var g in _gravities)
|
||||
{
|
||||
float w = mass * g;
|
||||
pd.Dropdown.options.Add(new TMP_Dropdown.OptionData(Mathf.RoundToInt(w) + " Í"));
|
||||
}
|
||||
pd.Dropdown.value = 0;
|
||||
pd.Dropdown.RefreshShownValue();
|
||||
}
|
||||
_checkButton.onClick.RemoveAllListeners();
|
||||
_checkButton.onClick.AddListener(CheckAll);
|
||||
_resultText.alpha = 0f;
|
||||
}
|
||||
|
||||
void CheckAll()
|
||||
{
|
||||
float mass = _astronautRb != null ? _astronautRb.mass : 75f;
|
||||
int correct = 0;
|
||||
PlanetDropdown[] planetDropdowns = FindObjectsOfType<PlanetDropdown>();
|
||||
foreach (var pd in planetDropdowns)
|
||||
{
|
||||
int planetIndex = pd.PlanetIndex;
|
||||
float correctWeight = mass * _gravities[planetIndex];
|
||||
int selectedIndex = pd.Dropdown.value - 1;
|
||||
if (selectedIndex < 0) continue;
|
||||
float selectedWeight = mass * _gravities[selectedIndex];
|
||||
if (Mathf.Abs(selectedWeight - correctWeight) < 1f)
|
||||
{
|
||||
correct++;
|
||||
pd.Dropdown.GetComponentInParent<Image>().color = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
pd.Dropdown.GetComponentInParent<Image>().color = Color.red;
|
||||
}
|
||||
}
|
||||
if (correct == planetDropdowns.Length)
|
||||
{
|
||||
_resultText.text = "Áëèñêó÷å! Öå ïðàâèëüíà â³äïîâ³äü!";
|
||||
_resultText.color = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_resultText.text = "Ìàéæå! Ñïðîáóé ùå ðàç";
|
||||
_resultText.color = Color.red;
|
||||
}
|
||||
StartCoroutine(ShowText());
|
||||
}
|
||||
|
||||
IEnumerator ShowText()
|
||||
{
|
||||
float t = 0f;
|
||||
while (t < 1f) { t += Time.deltaTime * 2f; _resultText.alpha = t; yield return null; }
|
||||
yield return new WaitForSeconds(3f);
|
||||
t = 1f;
|
||||
while (t > 0f) { t -= Time.deltaTime * 2f; _resultText.alpha = t; yield return null; }
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/PlanetWeight.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/PlanetWeight.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a3b19f6fbf62354185f8be3c13b58c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Asrtronaut/SecretDropdown.cs
Normal file
32
Assets/Scripts/Asrtronaut/SecretDropdown.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
public class SecretDropdown : MonoBehaviour
|
||||
{
|
||||
public enum SecretPlanet
|
||||
{
|
||||
煖莊<EFBFBD>, 竟簇債녜, 쭤張調, 犬<EFBFBD>琢, 璥猝, 蛇놋儼, 邏膣存, 到陝, 袞綎艙, 헌佾<EFBFBD>
|
||||
}
|
||||
|
||||
[SerializeField] private TMP_Dropdown _dropdown;
|
||||
[SerializeField] private SecretPlanet _planet;
|
||||
[SerializeField] private TextMeshProUGUI _planetNameText;
|
||||
|
||||
public TMP_Dropdown Dropdown => _dropdown;
|
||||
public int PlanetIndex => (int)_planet;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (_planetNameText != null)
|
||||
_planetNameText.text = _planet.ToString();
|
||||
_dropdown.onValueChanged.AddListener(OnValueChanged);
|
||||
}
|
||||
|
||||
void OnValueChanged(int index)
|
||||
{
|
||||
if (_planetNameText != null)
|
||||
_planetNameText.text = _planet.ToString();
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/SecretDropdown.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/SecretDropdown.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4254f48f2352dd24c9a198caadfa13c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
88
Assets/Scripts/Asrtronaut/SecretPlanetWeight.cs
Normal file
88
Assets/Scripts/Asrtronaut/SecretPlanetWeight.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SecretPlanetWeight : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI _resultText;
|
||||
[SerializeField] private Button _checkButton;
|
||||
[SerializeField] private Rigidbody _astronautRb;
|
||||
|
||||
private const float _earthGravity = 9.81f;
|
||||
float[] _gravities = { 274f, 3.7f, 8.87f, 1.62f, 3.71f, 24.79f, 10.44f, 8.69f, 11.15f, 9.81f };
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
RebuildDropdowns();
|
||||
}
|
||||
|
||||
void RebuildDropdowns()
|
||||
{
|
||||
float mass = _astronautRb != null ? _astronautRb.mass : 75f;
|
||||
SecretDropdown[] secretDropdowns = FindObjectsOfType<SecretDropdown>(true);
|
||||
foreach (var sd in secretDropdowns)
|
||||
{
|
||||
sd.Dropdown.ClearOptions();
|
||||
sd.Dropdown.options.Add(new TMP_Dropdown.OptionData("Îáðàòè"));
|
||||
foreach (var g in _gravities)
|
||||
{
|
||||
float weightN = mass * g;
|
||||
float massKg = weightN / _earthGravity;
|
||||
sd.Dropdown.options.Add(new TMP_Dropdown.OptionData(Mathf.RoundToInt(massKg) + " êã"));
|
||||
}
|
||||
sd.Dropdown.value = 0;
|
||||
sd.Dropdown.RefreshShownValue();
|
||||
}
|
||||
_checkButton.onClick.RemoveAllListeners();
|
||||
_checkButton.onClick.AddListener(CheckAll);
|
||||
_resultText.alpha = 0f;
|
||||
}
|
||||
|
||||
void CheckAll()
|
||||
{
|
||||
float mass = _astronautRb != null ? _astronautRb.mass : 75f;
|
||||
int correct = 0;
|
||||
SecretDropdown[] secretDropdowns = FindObjectsOfType<SecretDropdown>(true);
|
||||
foreach (var sd in secretDropdowns)
|
||||
{
|
||||
int planetIndex = sd.PlanetIndex;
|
||||
float correctWeightN = mass * _gravities[planetIndex];
|
||||
float correctMassKg = correctWeightN / _earthGravity;
|
||||
int selectedIndex = sd.Dropdown.value - 1;
|
||||
if (selectedIndex < 0) continue;
|
||||
float selectedWeightN = mass * _gravities[selectedIndex];
|
||||
float selectedMassKg = selectedWeightN / _earthGravity;
|
||||
if (Mathf.Abs(selectedMassKg - correctMassKg) < 1f)
|
||||
{
|
||||
correct++;
|
||||
sd.Dropdown.GetComponentInParent<Image>().color = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
sd.Dropdown.GetComponentInParent<Image>().color = Color.red;
|
||||
}
|
||||
}
|
||||
if (correct == secretDropdowns.Length)
|
||||
{
|
||||
_resultText.text = "Áëèñêó÷å! Öå ïðàâèëüíà â³äïîâ³äü!";
|
||||
_resultText.color = Color.green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_resultText.text = "Ìàéæå! Ñïðîáóé ùå ðàç";
|
||||
_resultText.color = Color.red;
|
||||
}
|
||||
StartCoroutine(ShowText());
|
||||
}
|
||||
|
||||
IEnumerator ShowText()
|
||||
{
|
||||
float t = 0f;
|
||||
while (t < 1f) { t += Time.deltaTime * 2f; _resultText.alpha = t; yield return null; }
|
||||
yield return new WaitForSeconds(3f);
|
||||
t = 1f;
|
||||
while (t > 0f) { t -= Time.deltaTime * 2f; _resultText.alpha = t; yield return null; }
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Asrtronaut/SecretPlanetWeight.cs.meta
Normal file
11
Assets/Scripts/Asrtronaut/SecretPlanetWeight.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64282c7b6bc4c73498089be8b1864a09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user