예제 #1
0
    IEnumerator SetShield()
    {
        while (!GetComponentInChildren <ShieldHealthDefence>()) //Waits until the shield is created on server
        {
            yield return(new WaitForEndOfFrame());
        }
        ShieldHealthDefence SP = GetComponentInChildren <ShieldHealthDefence>();

        Shield          = SP.gameObject;
        SP.scale_factor = 2.5f;//Rescales obj

        /*This changes the shield bar from a local shield bar object to the main shield bar
         * provided that the player who owns it is the one who is connected locally.
         * since player_interface_show would only be instantiated if Start() was executed
         * locally,the follwing check would be true only if the owner is playing locally on
         * that instance of the game running.*/
        if (player_interface_show)
        {
            SP.health_bar_show = player_interface_show.GetComponentsInChildren <Slider>()[3].gameObject as GameObject;
            SP.hp_string       = SP.health_bar_show.GetComponentInChildren <Text>();
            SP.hp_string.text  = "<b>" + SP.HP + "</b>";
            SP.hp_bar          = SP.health_bar_show.GetComponentInChildren <Slider>().GetComponent <RectTransform
                                                                                                    >();
            SP.maxWidth = SP.hp_bar.rect.width;
        }
        CmdSetShieldIdOnServer(Shield);
    }
예제 #2
0
 IEnumerator WaitForBlock(Collider col)
 {
     /*Only block if:
      * not trying to block another bullet(target_focus is true)
      * shield isnt regenerating (which would happen if the shield's HP gone to zero and hasn't fully generated)
      * the collider still exists
      * the collider isn't a trigger = which would go thru shield any way*/
     if (!Shield)
     {
         yield break;
     }
     else
     {
         ShieldHealthDefence SP = Shield.GetComponent <ShieldHealthDefence>();
         while (target_focus && !SP.regen && col && !col.isTrigger)
         {
             /*Wait until its gets 2 units away or it disappears*/
             if (Math.Abs(
                     Vector3.Distance(col.gameObject.transform.position, ptr.position))
                 < 2f)
             {
                 float       start_block       = Time.realtimeSinceStartup;
                 const float MAX_BLOCKING_TIME = 2;
                 /*Look at the bullet and block until it disappears.*/
                 target_focus = false;
                 StartShieldBlocking();
                 ptr.LookAt(col.transform);
                 while (col &&
                        Time.realtimeSinceStartup < start_block + MAX_BLOCKING_TIME)
                 {
                     yield return(new WaitForFixedUpdate());
                 }
                 break;
             }
             yield return(new WaitForFixedUpdate());
         }
     }
     if (blocking)
     {
         target_focus = true;
         EndShieldBlocking();
     }
 }