Example #1
0
        private void OnTriggerExit2D(Collider2D collision)
        {
            if (!collision.name.StartsWith("INTER"))
            {
                return;
            }
            Interactable interactable = collision.GetComponent <Interactable>();

            interactable.ChangeState(false);
            if (interactable == currentInteractable)
            {
                currentInteractable = null;
            }
        }
Example #2
0
        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);
        }
Example #3
0
 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;
 }
Example #4
0
 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;
     }
 }
Example #5
0
    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;
                }
            }
        }
    }
Example #6
0
 //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();
         }
     }
 }