Beispiel #1
0
 private void RegisterHit(RaycastHit2D hit)
 {
     if (hit.collider.gameObject.CompareTag("Money"))
     {
         DestroyObject(hit.collider.gameObject);
         if (collectSound != null)
         {
             AudioSource.PlayClipAtPoint(collectSound, Camera.main.transform.position);
         }
         money += 25;
     }
     else if (hit.collider.gameObject.CompareTag("FearPickup"))
     {
         DestroyObject(hit.collider.gameObject);
         if (collectFear != null)
         {
             AudioSource.PlayClipAtPoint(collectFear, Camera.main.transform.position);
         }
         if (fearEnergy < fearEnergyMax)
         {
             fearEnergy       += 2;
             fearEnergy        = Mathf.Min(fearEnergy, fearEnergyMax);
             fearDecayCooldown = fearDecayCooldownMax;
         }
         else
         {
             money += 50;
         }
     }
     else if (hit.collider.gameObject.CompareTag("Person"))
     {
         Person2 p = hit.collider.gameObject.GetComponent <Person2>();
         p.DisplayHP();
     }
     else if (hit.collider.gameObject.CompareTag("Furniture"))
     {
         Furniture f = hit.collider.gameObject.GetComponent <Furniture>();
         f.DisplayHP();
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (currentRoomNumber < RoomsOpen && hit.collider.gameObject.CompareTag("Triangle Up"))
         {
             MoveUp();
         }
         else if (currentRoomNumber > 0 && hit.collider.gameObject.CompareTag("Triangle Down"))
         {
             MoveDown();
         }
     }
     if (!GameVars.IsNight)
     {
         RegisterHitDaytime(hit);
     }
     else if (Input.GetMouseButtonDown(0))
     {
         if (currentAbility != null && currentAbility != listAbilities[1] && currentAbility != listAbilities[4])
         {
             if (hit.collider.gameObject.CompareTag("Room") || hit.collider.gameObject.CompareTag("Node") ||
                 hit.collider.gameObject.CompareTag("Furniture") || hit.collider.gameObject.CompareTag("Person"))
             {
                 if (currentAbility.CanUse())
                 {
                     currentAbility.UseAbility(hit);
                     currentAbility = null;
                 }
             }
         }
         else if (hit.collider.gameObject.CompareTag("Hazard"))
         {
             hit.collider.GetComponent <Hazard>().Fade();
         }
         else if (currentAbility == listAbilities[4] && listAbilities[4].CanUse() && hit.collider.gameObject.CompareTag("Person"))
         {
             currentAbility.UseAbility(hit);
             currentAbility = null;                // possession
         }
         else if (hit.collider.gameObject.CompareTag("Furniture"))
         {
             Furniture f = hit.collider.gameObject.GetComponent <Furniture>();
             if (currentAbility == listAbilities[1] && listAbilities[1].CanUse())
             {
                 currentAbility.UseAbility(hit);
                 currentAbility = null;
             }
             else if (f is Lamp)
             {
                 if (lampSwitch != null)
                 {
                     AudioSource.PlayClipAtPoint(lampSwitch, Camera.main.transform.position);
                 }
                 Lamp l = hit.collider.gameObject.GetComponent <Lamp>();
                 if (l.Durability > 0)
                 {
                     l.Flip();
                 }
             }
             else if (f is Trap && !(f as Trap).Used)
             {
                 Debug.Log("Activating");
                 (f as Trap).Activate();
             }
         }
     }
 }