protected void OnTriggerStay2D(Collider2D col) { // Debug.Log("this trigger entered another"); //Is the other object a bubble, and not the bubble we currently have? if (col.collider2D.CompareTag("Bubble") && col.gameObject != otherBubble) { Bubble bubble = col.gameObject.GetComponent <Bubble>(); if (bubble == null || !(bubble.state is InEquationState)) { onBubble = true; otherBubble = col.gameObject; } } }
public void SetPermanentNumber(int num) { //Add new permanent bubble GameObject bubbleGO = BubbleFactory.Instance.SpawnBubble(num, transform.position); Bubble bubble = bubbleGO.GetComponent <Bubble>(); CombineWith(bubble); //make sure they can't move the bubble StuckEquationState stuckState = bubbleGO.AddComponent <StuckEquationState>(); bubble.ChangeState(stuckState); isPermanent = true; if (bubble.number > 9) { renderer.enabled = false; } }
//Combine this bubble with another, by adding public override void CombineWith(Bubble other) { //Add their results together int result = other.number + bubble.number; if (result <= 9) { //Spawn a bubble with number = result BubbleFactory.Instance.SpawnBubble(result, transform.position); } else { //if result two digit number, spawn one bubble for each digit int digitOne = result % 10; int digitTwo = result / 10; BubbleFactory.Instance.SpawnBubble(digitOne, transform.position + spawnOffset); BubbleFactory.Instance.SpawnBubble(digitTwo, transform.position - spawnOffset); } UserRecorder.Instance.CombineBubbles(bubble.number, other.number); //Destroy both bubbles GameObject.Destroy(other.gameObject); GameObject.Destroy(gameObject); }
//Put other bubble script into this equation public override void CombineWith(Bubble other) { //Don't switch if we have a permanent bubble already if (isPermanent && bubble != null) { return; } //Debug.Log("holder combo ith bubble?"+other.number); //release current bubble ReleaseBubble(); //Hold the new bubble bubble = other; InEquationState equationState = other.GetComponent <InEquationState>(); other.ChangeState(equationState); equationState.holder = this; other.transform.position = transform.position; //attempt to solve the equation with the new bubble equation.AttemptSolve(); }
public abstract void CombineWith(Bubble bubble);
protected void Start() { bubble = gameObject.GetComponent <Bubble>(); }
protected virtual void Start() { master = gameObject.GetComponent <Bubble>(); }