private void pickUpBox() { if (holding) { boxInst.GetComponent <BoxCollider2D>().isTrigger = false; boxInst.GetComponent <Rigidbody2D>().simulated = true; gameObject.GetComponent <Animator>().SetBool("holding", false); boxInst.transform.parent = null; holding = false; speedModifier = 1f; } else if (inGrabRange && !holding) { if (boxInst.transform.parent != null) { boxInst.transform.parent.gameObject.GetComponent <PlayerController>().holding = false; boxInst.transform.parent.gameObject.GetComponent <PlayerController>().boxInst = null; boxInst.transform.parent.gameObject.GetComponent <Animator>().SetBool("holding", false); } gameObject.GetComponent <Animator>().SetBool("holding", true); boxInst.GetComponent <BoxCollider2D>().isTrigger = true; holding = true; //Mathf.Sign(gameObject.transform.position.x - boxInst.transform.position.x) //boxInst.transform.position = gameObject.transform.position + new Vector3(-0.25f, 0.22f, -1.0f); if (facingRight) { boxInst.transform.position = gameObject.transform.position + new Vector3(0.25f, 0.22f, -1.0f); } else { boxInst.transform.position = gameObject.transform.position + new Vector3(-0.25f, 0.22f, -1.0f); } boxInst.transform.parent = gameObject.transform; boxInst.GetComponent <Rigidbody2D>().simulated = false; if (boxInst.isBoxHeavy()) { speedModifier = heavyBoxModifier; } } }
private void IdNetworkkBoxPandoraInServer(BoxController boxController) { if (boxController != null) { ExtractBoxPandoraServer(boxController.GetComponent <NetworkIdentity>().netId); } }
private void OnTriggerStay(Collider other) { if (Input.GetKeyDown(KeyCode.E) && _pickedUpBox == null) { _pickedUpBox = other.GetComponent <BoxController>(); if (_pickedUpBox != null && _pickedUpBox.Model.CanMoveBy(Game.Instance.PrincessCake.Model)) { Game.Instance.Logger.Info("Picked Up box: " + _pickedUpBox); _pickedUpBox.GetComponent <Rigidbody>().isKinematic = true; _pickedUpBox.transform.position = transform.position; _pickedUpBox.transform.SetParent(transform); StopAllCoroutines(); StartCoroutine(HandleInput()); _audio.TryPlaySFX(_onPickUp); } else { StopAllCoroutines(); _pickedUpBox = null; } } }
/// <summary> /// Called at start to initially highlight the StartBox /// </summary> private void firstHighlight() { _CurrentlyHighlighted = _StartBox; // Get Image component of the _StartBox Image _boxImage = _StartBox.GetComponent <Image> (); // Set the sprite of _StartBox to 'selected' sprite _boxImage.sprite = SpritesManager.Sprites [0]; _CurrentlyHighlighted.setIsHighlighted(true); }
public void CheckBox(BoxController currentBox) { GameObject.Find("Chute").GetComponent <Animator>().SetTrigger("eatPackage"); BoxController correctOrder = null; bool completed = true; foreach (BoxController order in orders) { completed = true; foreach (string key in order.fields) { if (order.attributes[key] != currentBox.attributes[key]) { completed = false; Debug.Log("Failed this order"); break; } } if (completed && (order.isFragile == currentBox.isFragile) && (order.isHeavy == currentBox.isHeavy)) { if (currentBox.isSafe == true) { correctOrder = order; break; } else { Debug.Log("You passed an unsafe box. Shame on you."); scoring.subtractScore(20); break; } } } currentBox.GetComponent <BoxController>().onDeath(); if (correctOrder != null) { Remove(correctOrder); Debug.Log("Correct"); GameObject.Find("Chute").GetComponent <Animator>().SetBool("correct", true); } else { GameObject.Find("Chute").GetComponent <Animator>().SetBool("correct", false); scoring.subtractScore(20); Debug.Log("Failed"); } }
public void SetConnectedBoxes(BoxController b1, BoxController b2) { box1 = b1; box2 = b2; rbBox1 = b1.GetComponent <Rigidbody>(); rbBox2 = b2.GetComponent <Rigidbody>(); lineRenderer = GetComponent <LineRenderer>(); box1.BoxDestroyEvent += BoxDestroyed; box2.BoxDestroyEvent += BoxDestroyed; Draw(); }
private IEnumerator HandleInput() { yield return(new WaitForSeconds(_initialDelayBeforeAllowDrop)); while (_pickedUpBox != null) { if (Input.GetKeyDown(KeyCode.E)) { _pickedUpBox.GetComponent <Rigidbody>().isKinematic = false; _pickedUpBox.transform.SetParent(null); _pickedUpBox = null; _audio.TryPlaySFX(_onPut); } yield return(null); } }
/// <summary> /// Highlight the specified p_Box. /// </summary> /// <param name="p_Box">P box.</param> public static void highlight(BoxController p_Box) { // Get the Image component of the newly selected box Image _boxImage = p_Box.GetComponent <Image> (); // Set the sprite of newly selected box to the 'selected' sprite _boxImage.sprite = SpritesManager.Sprites [0]; // Set the currently highlighted box to now become the previously highlighted box _PreviouslyHighlighted = _CurrentlyHighlighted; // Unhighlight this box _PreviouslyHighlighted.unHighlight(); _PreviouslyHighlighted.setIsHighlighted(false); // Now set the currently highlighted box to be the parameter that was passed to this method _CurrentlyHighlighted = p_Box; _CurrentlyHighlighted.setIsHighlighted(true); }
/*Some interactions. The first implementes is hold boxes*/ private void interactions() { if (boxHold != null) { if (PlayerController.instance.FrontToRight) { boxHold.transform.position = new Vector3(transform.position.x + 1, transform.position.y, transform.position.z); } else { boxHold.transform.position = new Vector3(transform.position.x - 1, transform.position.y, transform.position.z); } boxHold.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); if (!PlayerController.instance.HoldAction && boxHold != null) { boxHold.gameObject.layer = 15; boxHold = null; PlayerController.instance.Anim.SetBool("holding", false); } } }
public void OnMainBoxGlowing(BoxController boxController) { changeToColor = boxController.GetComponent <SpriteRenderer>().color; //Debug.Log("Main box glowing in " + changeToColor); isMainBoxGlowing = true; }