void questionGenerate()
{
if (qList.Count > 0)
{
randQ = Random.Range(0, qList.Count); //если не нужен рандом это удалить
crntQ = qList[randQ] as QuestionList;
qText.text = crntQ.question;
List<string> answers = new List<string>(crntQ.answers);
for (int i = 0; i < crntQ.answers.Length; i++)
{
int rand = Random.Range(0, answers.Count);
answersText[i].text = answers[rand];
answers.RemoveAt(rand);
}
qList.RemoveAt(qList[randQ]);
}
else
{
Debug.Log("Вы прошли игру");
}
}
[SerializeField] GameObject shootPF;
using UnityEngine;
using Cinemachine;
public class CameraShaker : MonoBehaviour {
public CinemachineVirtualCamera _vCam;
private CinemachineBasicMultiChannelPerlin _vCamNoise;
void Start()
{
if (_vCam != null)
_vCamNoise = _vCam.GetCinemachineComponent<Cinemachine.CinemachineBasicMultiChannelPerlin>();
}
void Update()
{
// _isShake = Input.GetKey(KeyCode.Space);
if (Input.GetKey(KeyCode.Space))
{
_vCamNoise.m_AmplitudeGain = 2f;
_vCamNoise.m_FrequencyGain = 1.2f;
}
else
{
_vCamNoise.m_AmplitudeGain = 0f;
}
}
}
private void Update()
{
transform.position = transform.position + transform.forward * 5f * Time.deltaTime;
}
using UnityEngine;
public class CamHolder : MonoBehaviour
{
[Header("TargetObj")]
[SerializeField] Rigidbody carPhysics;
[Header("CamSettings")]
[SerializeField] Transform _сamHolder;
[SerializeField] float _camSpeedRotate=1f;
[SerializeField] bool _rotateMode;
[SerializeField] float _speedToDefault = 360f;
[SerializeField] float _timerToSetDefoult=1f;
float _currentTimerToSet;
float mouseX, mouseY;
float _camYaw;
float _camPitch;
const float k_bottomClamp=-90f;
const float k_topClamp = 90f;
private void Update()
{
GetMouseInput();
}
void GetMouseInput()
{
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
if (Input.GetMouseButton(1))
{
Debug.Log("Test");
_rotateMode=true;
_currentTimerToSet = _timerToSetDefoult;
}
if (_rotateMode)
{
_currentTimerToSet -= Time.deltaTime;
if(!(_currentTimerToSet>0))_rotateMode = false;
}
}
private void FixedUpdate()
{
transform.position = carPhysics.transform.position;
transform.rotation = carPhysics.transform.rotation;
}
private void LateUpdate()
{
CameraRotation();
}
private void CameraRotation()
{
if (_rotateMode)
{
_camYaw += mouseX * _camSpeedRotate;
_camPitch -= mouseY * _camSpeedRotate;
_camYaw = Clamper(_camYaw, float.MinValue, float.MaxValue);
_camPitch = Clamper(_camPitch, k_bottomClamp, k_topClamp);
_сamHolder.transform.rotation = Quaternion.Euler(_camPitch,
_camYaw, 0.0f);
}
else
{
_сamHolder.transform.localRotation = Quaternion.RotateTowards(_сamHolder.transform.localRotation,Quaternion.Euler(Vector3.zero),_speedToDefault*Time.deltaTime);
}
}
float Clamper(float curAngle,float clampMin,float clampMax)
{
if (curAngle < -360f) curAngle += 360f;
if (curAngle > 360f) curAngle -= 360f;
return Mathf.Clamp(curAngle, clampMin, clampMax);
}
}
[SerializeField] BoxCollider2D SpawnArea;
private void Randomposition()
{
Bounds bounds = SpawnArea.bounds;
float x =SpawnArea.transform.position.x+ Random.Range(bounds.min.x, bounds.max.x);
float y = SpawnArea.transform.position.y+Random.Range(bounds.min.y, bounds.max.y);
//перед изменением надо проверить на наличие змейки в точке
// не уверен что сработает , без должно тож работать
Vector3 newpos= new Vector3(Mathf.Round(x) + 0.5f, Mathf.Round(y) + 0.5f, -1f); //0.5 из за того что объект равен 1,1
if (IsGetSnake(newpos))
{
Randomposition();
return;
}
transform.position = newpos;
}
bool IsGetSnake(Vector3 pos)
{
bool shake = false;
if (Physics.Raycast(pos + Vector3.forward, -Vector3.forward, out RaycastHit hit))
{
if (hit.transform.tag == "snake")
{
shake = true;
}
}
return shake;
}
private void Start()
{
Randomposition();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "snake")
{
Randomposition();
}
}
_playerRb.AddForce(_playerRb.transform.up * jumpHeight,ForceMode2D.Impulse);
[SerializeField] GameObject _gO1;
[SerializeField] GameObject _gO2;
private void Update()
{
GameOBJ1Rotator();
}
private void LateUpdate()
{
_gO2.transform.rotation = Quaternion.Euler(0, GetAngle(), 0); //задаем
Debug.Log("GO1 :" + _gO1.transform.eulerAngles.y + " GO2 :" + _gO2.transform.eulerAngles.y); // дебаг для вращения
}
void GameOBJ1Rotator() ///это не надо просто для наглядности, как сломать вращение
{
_gO1.transform.rotation *= Quaternion.Euler(Vector3.one*90f*Time.deltaTime);
}
float GetAngle() //получаем градусы таргет объекта
{
float angle = _gO1.transform.rotation.eulerAngles.y;
return angle;
}
[SerializeField] float rotationSpeed = 360f;
[SerializeField] float _inputPower=5f;
float _inputY;
private void Update()
{
_inputY -= Input.GetAxis("Mouse Y") * _inputPower;
_inputY = Mathf.Clamp(_inputY, -50f, 50f);
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(Vector3.up * _inputY), rotationSpeed * Time.deltaTime);
}