// Use OnCollisionStay2D() to avoid falling through the ground. private void OnCollisionStay2D(Collision2D collision) { if (tag.Contains(GlobalVariables.tagFalling) == true && collision.gameObject == ground) { if (GlobalVariables.FlipCoin() == true) { GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic; if (tag.Contains(GlobalVariables.tagPrimaryRunaway) == true) { tag = GlobalVariables.tagPrimaryRunaway + GlobalVariables.tagLeft; } else { tag = GlobalVariables.tagSecondaryRunaway + GlobalVariables.tagLeft; } } else if (GlobalVariables.FlipCoin() == false) { GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Kinematic; if (tag.Contains(GlobalVariables.tagPrimaryRunaway) == true) { tag = GlobalVariables.tagPrimaryRunaway + GlobalVariables.tagRight; } else { tag = GlobalVariables.tagSecondaryRunaway + GlobalVariables.tagRight; } } } }
private void SpawnRunaway(string runaway) { SetRunaway(runaway); if (GlobalVariables.FlipCoin() == true) { runawayInstance = Instantiate(runawayPrefab, GlobalVariables.gameCanvas.transform, false); runawayInstance.transform.localPosition = runawayPrefab.transform.localPosition; runawayInstance.tag = runaway + "Left"; } else { runawayInstance = Instantiate(runawayPrefab, GlobalVariables.gameCanvas.transform, false); runawayInstance.transform.localPosition = runawayPrefab.transform.localPosition * new Vector2(-1, 1); runawayInstance.tag = runaway + "Right"; } }