private void OnTriggerExit2D(Collider2D collision) { if (!collision.name.StartsWith("INTER")) { return; } Interactable interactable = collision.GetComponent <Interactable>(); interactable.ChangeState(false); if (interactable == currentInteractable) { currentInteractable = null; } }
private void OnTriggerEnter2D(Collider2D collision) { if (!collision.name.StartsWith("INTER")) { return; } Interactable interactable = collision.GetComponent <Interactable>(); if (interactable == null) { return; } if (currentInteractable != null) { currentInteractable.ChangeState(false); } currentInteractable = interactable; currentInteractable.ChangeState(true); }
protected virtual void DropItem() { carryingItem.ChangeState(Interactable.States.off); carryingItem.transform.position = effectorBox.transform.position; SpriteLock[] itemSprites = carryingItem.GetComponentsInChildren <SpriteLock>(); foreach (SpriteLock sprite in itemSprites) { sprites.Remove(sprite); } carryingItem.transform.parent = carryingItem.baseParent; foreach (Collider2D thisCollider in carryingItem.GetComponents <Collider2D>()) { thisCollider.enabled = true; } if (carryingItem.rb != null) { carryingItem.rb.bodyType = carryingItem.baseType; } carryingItem = null; }
protected virtual void PickUpItem(Interactable item) { carryingItem = item; carryingItem.ChangeState(Interactable.States.on); carryingItem.transform.parent = transform; carryingItem.transform.localPosition = Vector3.up; SpriteLock[] itemSprites = carryingItem.GetComponentsInChildren <SpriteLock>(); foreach (SpriteLock sprite in itemSprites) { sprites.Add(sprite); } foreach (Collider2D thisCollider in carryingItem.GetComponents <Collider2D>()) { thisCollider.enabled = false; } if (carryingItem.rb != null) { carryingItem.rb.bodyType = RigidbodyType2D.Kinematic; } }
protected virtual void Interact() { if (carryingItem != null) { DropItem(); } else { Interactable thisObject = GetEffectorObject(); if (thisObject != null) { switch (thisObject.interactType) { case Interactable.InteractTypes.lever: thisObject.ChangeState(!thisObject.IsActive()); break; case Interactable.InteractTypes.holdable: PickUpItem(thisObject); break; } } } }
//Perform actions based on the Type of button (Blue, Red, Purple) private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { if (world.isRetro) { if (type == 0) { if (!isDown) { soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } door.ChangeState(1); isDown = true; } if (type == 1) { soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); if (door.state == 0) { door.ChangeState(1); } else { door.ChangeState(0); } } if (type == 2) { door.ChangeState(1); soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } } } if (collision.tag == "Interactable") { if (type == 0) { if (!isDown) { soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } door.ChangeState(1); isDown = true; } if (type == 1) { if (door.state == 0) { door.ChangeState(1); soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } else { door.ChangeState(0); soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } } if (type == 2) { soundGen.clip = Resources.Load <AudioClip>("Assets/Music/buttonRet"); soundGen.Play(); } } }