Esempio n. 1
0
	void VerticalCollisions(ref Vector3 velocity) { //проверка RayCasta по y
		float directionY = Mathf.Sign (velocity.y); //если число с минусом то 0, если с + то 1
		float rayLenght = Mathf.Abs(velocity.y) + skinWidth;  //убираем знак 

		for (int i = 0; i< verticalRayCount; i++) {  //рисуем четыре линии
			Vector2 rayOrigin = (directionY == -1)?raycastOrigins.bottomLeft:raycastOrigins.topLeft;  //присваиваем значение в зависимости от знака
			rayOrigin += Vector2.right * (verticalRaySpacing * i + velocity.x);
			RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLenght, collisionMask);  //пускаем луч для проверки с колизией слоя
			Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLenght, Color.red); //выводи луч

			if (hit) {

				if (hit.collider.tag == "Through") {
					if (directionY == 1 || hit.distance == 0) {
						soundSC.track("prize");
						money = money.GetComponent<Money>();
						money.createMoney (rayOrigin);
					}
					if (collisions.fallingThroughPlatform) {
					}
					if (playerInput.y == -1) {
						
					}
				}

				velocity.y = (hit.distance - skinWidth) * directionY;
				rayLenght = hit.distance;


				collisions.below = directionY == -1;
				collisions.above = directionY == 1;
			} 
		}


	}