public Pill(int id, Transform parent, Transform self, Grid grid) { Id = id; PillParts = new Dictionary <string, PillPart> { { "first", null }, { "second", null } }; PillParts["first"] = new PillPart(id, true, grid); PillParts["first"].PositionColumn = Constants.InitPositionColumnPillPart0; PillParts["second"] = new PillPart(id, false, grid); PillParts["second"].PositionColumn = Constants.InitPositionColumnPillPart1; PillParts["first"].PositionRow = PillParts["second"].PositionRow = Constants.Rows - 1; self.name = "pill" + Id; SpriteRenderer[] allChildren = self.GetComponentsInChildren <SpriteRenderer>(); List <GameObject> pillParts = new List <GameObject>(); foreach (SpriteRenderer child in allChildren) { pillParts.Add(child.gameObject); } PillParts["first"].Behaviour = pillParts[0].GetComponent <PillPartBehaviour>(); PillParts["second"].Behaviour = pillParts[1].GetComponent <PillPartBehaviour>(); PillParts["first"].Behaviour.PillPartObj = PillParts["first"]; PillParts["second"].Behaviour.PillPartObj = PillParts["second"]; State = PillState.HORIZONTAL; }
// called when pill is thrown public void OnThrow() { // play the sound throwSound.Play(); // show the trail renderer GetComponent <TrailRenderer>().enabled = true; // allow for gravity forces GetComponent <Rigidbody2D>().isKinematic = false; // make the collider normal size GetComponent <CircleCollider2D>().radius = Constants.PillColliderRadiusNormal; State = PillState.Thrown; }
public void Init(string medName, int dosage, Sprite pillSprite, int canSplit, Vector3 pos) { this.medName = medName; this.dosage = dosage; this.canSplit = canSplit; gameObject.GetComponent <SpriteRenderer>().sprite = pillSprite; // if this pill can be split, load the sprite for half a tab if (canSplit != 0) { pillSpriteHalf = Resources.Load <Sprite>("Sprites/Meds/" + medName + "_tab_half"); } transform.localScale = new Vector3(0.1f, 0.1f, 0f); // scale sprite smaller Time.timeScale = 1.0f; Time.fixedDeltaTime = 0.02F * Time.timeScale; GetComponent <CircleCollider2D>().radius = Constants.PillColliderRadiusBig; State = PillState.BeforeThrown; }