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;
}
}