float GetFinalAngle(LineSwitchAngle entryAngle, LineSwitchAngle currentAngle) { float finalAngle = (float)entryAngle - (float)currentAngle; if (finalAngle < 0) { finalAngle = 360 + finalAngle; } return(finalAngle); }
void OnCollisionEnter2D(Collision2D collision) { Ball ball = collision.gameObject.GetComponent <Ball>(); if (ball != null) { locked = true; float ballAngle = (float)ball.GetAngle(); LineSwitchAngle entryAngle = entryAngles[ballAngle]; float finalAngle = GetFinalAngle(entryAngle, currentAngle); // the ball didn't enter from the right direction if (!passageRules[finalAngle]) { ball.Hit(); } } }
// Use this for initialization void Start() { currentAngle = startingAngle; currentAngleIndex = switchOrder.IndexOf(currentAngle); UpdateAngle(); }
void SwitchAngle() { currentAngleIndex = (currentAngleIndex + 1) % switchOrder.Count; currentAngle = switchOrder[currentAngleIndex]; UpdateAngle(); }