if (Input.GetKeyDown(KeyCode.Z) && !isPressed)
{
target = turretParent;
distance = dist;
heightPosition = height;
isPressed = true;
}
if (Input.GetKeyDown(KeyCode.Z) && isPressed)
{
target = turretBarrel;
distance = 0f;
heightPosition = 0f;
isPressed = false;
}
using UnityEngine;
public class Rotate : MonoBehaviour
{
float _currentSpeed;
float _targetSpeed;
[SerializeField] float _speedRotate;
const float c_acceleration = 20f;
const float c_di_acceleration = 10f;
float _acceleration;
private void Update()
{
_targetSpeed = Input.GetAxis("Mouse Y")*_speedRotate;
_acceleration = _targetSpeed != 0 ? c_acceleration : c_di_acceleration;
_currentSpeed = Mathf.MoveTowards(_currentSpeed, _targetSpeed, _acceleration * Time.deltaTime);
}
}
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 - это переменная где хранятся очки
}
using UnityEngine;
public class Player2dTest : MonoBehaviour
{
[SerializeField] Transform _wallLeft;
[SerializeField] Transform _wallRight;
Vector3 _targetTransf;
[SerializeField] float _speed = 5f;
Collider2D _myCol;
bool _isMove = true;
[SerializeField]bool _isWin;
private void Start()
{
_myCol= GetComponent<Collider2D>();
_targetTransf = _wallLeft.position;
}
private void Update()
{
if (_isMove)
{
_myCol.transform.position = Vector2.MoveTowards(_myCol.transform.position, _targetTransf, _speed * Time.deltaTime);
if (_myCol.transform.position == _targetTransf) NewTargetMove();
}
if (Input.GetKeyDown(KeyCode.Space))
{
EndGame();
}
}
void NewTargetMove()
{
if (_targetTransf != _wallRight.position) _targetTransf = _wallRight.position;
else _targetTransf = _wallLeft.position;
}
void EndGame()
{
_isMove = false;
if (_isWin) Debug.Log("You Win");
else Debug.Log("You Lose");
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag=="FirstPart") _isWin = true;
}
private void OnTriggerExit2D(Collider2D collision)
{
if(_isWin)_isWin = false;
}
}
using UnityEngine;
using UnityEngine.SceneManagement;
public class GoNextStage : MonoBehaviour
{
int item;
void PickUpIntem()
{
item++;
if (!(item < 15)) Loader();
}
void Loader()
{
SceneManager.LoadScene("Second"); //<=Название след сцены
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Item")
{
other.gameObject.SetActive(false);
PickUpIntem();
}
}
}