void OnCollisionEnter2D(Collision2D c) { if (c.gameObject.tag == "It") { SimpleSphereMovement ssm = c.gameObject.GetComponent <SimpleSphereMovement>(); // First figure out which axis is faster float v = Input.GetAxis("Vertical"); float h = Input.GetAxis("Horizontal"); if (Mathf.Abs(v) > Mathf.Abs(h)) { if (v > 0) { ssm.velocity = Vector2.up; } else // v < 0 { ssm.velocity = Vector2.down; } } else // abs(h) > abs(v) { if (h > 0) { ssm.velocity = Vector2.right; } else // h < 0 { ssm.velocity = Vector2.left; } } } }
void Start() { it = GameObject.FindWithTag("It").GetComponent <SimpleSphereMovement>(); }