public void OnCollisionEnter2D(Collision2D collision) { //C определнной вероятностью, при ударе об стенку мяч меняет свою траекторию if (collision.gameObject.CompareTag("border")) { if (CheckDirection == rb.velocity || CheckDirection == -rb.velocity) { timesOfSameDirection++; if (timesOfSameDirection >= 4) { float randX = Random.Range(-5, 0); Vector2 deriction = new Vector2(randX, 1); Vector2 force = deriction.normalized * speedArr[speedIndex]; rb.velocity = force; } } if (CheckDirection != rb.velocity) { CheckDirection = rb.velocity; } } if (collision.gameObject.CompareTag("border") || collision.gameObject.CompareTag("Collisioner")) { Instantiate(BorderCollisionEffect, transform.position, Quaternion.identity); float correction = Random.Range(0, 4); if (collision.gameObject.CompareTag("border") && correction == 1) { Bing.Play(); float randX = Random.Range(-5, 0); Vector2 deriction = new Vector2(randX, 1); Vector2 force = deriction.normalized * speedArr[speedIndex]; rb.velocity = force; } Exploide(); } void ActiveExplode() { isExploide = true; } void Exploide() { int layerMask = LayerMask.GetMask("blocks"); Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, Radius, layerMask); foreach (Collider2D col in colliders) { Collisioner block = GetComponent <Collisioner>(); if (block == null) { Destroy(gameObject); } else { block.BlockDestroyed(); } } } }
// Use this for initialization void Start() { arw = GetComponent <Rigidbody>(); tip = GameObject.Find("Tip").transform; target = GameObject.Find("Target").transform; state = 0; rotation = arw.transform.localRotation; position = arw.transform.localPosition; col = new Collisioner(tip, target); parent = arw.transform.parent; }