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("Вы прошли игру");
}
}
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);
using UnityEngine;
public class ParentUsing : MonoBehaviour
{
GameObject _targetGO;
bool UIVision;
void Update()
{
if (Input.GetKeyDown(KeyCode.E) && _targetGO != null)
{
ParentSet(_targetGO);
}
}
void ParentSet(GameObject newParentCursor)
{
gameObject.transform.parent = newParentCursor.transform;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Cursor")
{
UIVision = true;
_targetGO= other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
if(_targetGO==other.gameObject)_targetGO = null;
}
}
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Tester : MonoBehaviour
{
[SerializeField] List<Transform> _allPoint=new List<Transform>();
Transform _targetPos;
[SerializeField] Transform _playerPos;
[SerializeField] float _playerTargetDis;
[SerializeField] float _stopDistans;
[SerializeField] float _speed;
bool _isToPlayer;
private void Start()
{
SetAllPoint();
_targetPos = SelectRandom();
}
void SetAllPoint()
{
foreach (GameObject t in GameObject.FindGameObjectsWithTag("Point"))
{
_allPoint.Add(t.transform);
}
}
Transform SelectRandom()
{
int rand = Random.Range(0, (_allPoint.Count));
Debug.Log(rand);
return _allPoint[rand];
}
private void Update()
{
if (_isToPlayer) MoveToPlayer();
else MoveToPoint();
}
private void FixedUpdate()
{
_isToPlayer = SeePlayer();
}
void MoveToPoint()
{
transform.position = Vector3.MoveTowards(transform.position, _targetPos.position, _speed * Time.deltaTime); //заменить мб движение по нашмешу
if(Vector3.Distance(transform.position, _targetPos.position) < _stopDistans) _targetPos = SelectRandom();
}
void MoveToPlayer()
{
transform.position = Vector3.MoveTowards(transform.position, _playerPos.position, _speed * Time.deltaTime);
}
bool SeePlayer() //тут это от проекта зависит я сделал от дальности без поля зрения и тд
{
if (Vector3.Distance(transform.position, _playerPos.position) > _playerTargetDis) return false;
return true;
}
}
using UnityEngine;
public class Plus : MonoBehaviour
{
public string plusname;
public GameObject ReadyBall;
GameObject _colObj;
bool _IsCol;
private void Update()
{
if (_IsCol) Pluser();
}
void Pluser()
{
_colObj.SetActive(false);
GameObject newObj= Instantiate(ReadyBall, (_colObj.transform.position), Quaternion.identity);
newObj.transform.name = "CreateBy" + this.transform.name; ///For Debug
Destroy(_colObj);
Destroy(this.gameObject);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == plusname&&!_IsCol)
{
_colObj = collision.gameObject;
_IsCol = true;
}
}
}
void Start() //добавляем в старт что бы все отнулялость при запуске сцены
{
SetScoreZero();
}
public void SetScoreZero()
{
MyScore = 0; //MyScore - это переменная где хранятся очки
}