示例#1
0
 void OnCollisionEnter(Collision col)
 {
     if (!landed && col.gameObject.tag == "floor")
     {
         if (landsound)
         {
             audio.PlayOneShot(landsound);
         }
         landed = true;
     }
     else if (col.gameObject.tag == "block" ||
              col.gameObject.tag == "enemy")
     {
         if (powerup_active != PowerupType.Transparency)
         {
             if (hitsound)
             {
                 audio.PlayOneShot(hitsound);
             }
             rigidbody.AddForce(Vector3.up * knockback.y +
                                Vector3.forward * knockback.x,
                                ForceMode.Impulse);
         }
     }
     else if (col.gameObject.tag == "food")
     {
         if (powerup_active != PowerupType.Transparency)
         {
             if (eatsound)
             {
                 audio.PlayOneShot(eatsound);
             }
             FoodBehaviour food = col.gameObject.GetComponent <FoodBehaviour>();
             SceneBuilder.Instance.SendMessage("UpdateScore", food.food_type);
             Destroy(col.gameObject);
         }
     }
     else if (col.gameObject.tag == "powerup")
     {
         if (powerup_active == PowerupType.None)
         {
             if (eatsound)
             {
                 audio.PlayOneShot(eatsound);
             }
             PowerupBehaviour powerup = col.gameObject.GetComponent <PowerupBehaviour>();
             powerup_owned = powerup.powerup_type;
             PowerupDisplay.Instance.SendMessage("UpdateType", powerup_owned);
             Destroy(col.gameObject);
         }
     }
 }
 void reconstruction(GameObject player_clone, PowerupBehaviour pb, Collider collider, Vector3 old_cmd,
                     NodeBehaviour old_cn, GameObject old_tn)
 {
     player_clone.GetComponent <PlayerMovement>().move_speed_stored = collider.gameObject.GetComponent <PlayerMovement>().move_speed_stored;
     if (pb != null)
     {
         player_clone.GetComponent <PlayerController>().powerup = pb;
     }
     player_clone.GetComponent <PlayerMovement>().current_movement_direction = old_cmd;
     player_clone.GetComponent <PlayerMovement>().current_node = old_cn;
     player_clone.GetComponent <PlayerMovement>().target_node  = old_tn;
     PhotonNetwork.Destroy(collider.gameObject);
     if (pb != null)
     {
         player_clone.GetComponent <PlayerController>().setPowerState(true);
         player_clone.GetComponent <PlayerMovement>().init = true;
     }
 }
    void OnTriggerExit(Collider collider)
    {
        if (collider.tag == "PlayerContainer" && PlayerController.checkIsClientPlayer(collider.name))
        {
            Vector3 diff = collider.gameObject.transform.position - this.transform.position;
            if (collider.gameObject.GetComponent <PlayerController>().powerup != null)
            {
                diff /= 2;
            }
            if (x_warp_node && Mathf.Abs(diff.x) > 1.0f)
            {
                Vector3          old_cmd      = collider.gameObject.GetComponent <PlayerMovement>().current_movement_direction;
                NodeBehaviour    old_cn       = collider.gameObject.GetComponent <PlayerMovement>().current_node;
                GameObject       old_tn       = collider.gameObject.GetComponent <PlayerMovement>().target_node;
                string           player_name  = collider.gameObject.name.Substring(0, 7);
                Quaternion       rot          = collider.gameObject.transform.rotation;
                PowerupBehaviour pb           = collider.gameObject.GetComponent <PlayerController>().powerup;
                GameObject       player_clone = PhotonNetwork.Instantiate(player_name, new Vector3(
                                                                              -collider.gameObject.transform.position.x,
                                                                              collider.gameObject.transform.position.y,
                                                                              collider.gameObject.transform.position.z),
                                                                          rot);
                reconstruction(player_clone, pb, collider, old_cmd,
                               old_cn, old_tn);
            }
            if (z_warp_node && Mathf.Abs(diff.z) > 1.0f)
            {
                Vector3          old_cmd      = collider.gameObject.GetComponent <PlayerMovement>().current_movement_direction;
                NodeBehaviour    old_cn       = collider.gameObject.GetComponent <PlayerMovement>().current_node;
                GameObject       old_tn       = collider.gameObject.GetComponent <PlayerMovement>().target_node;
                string           player_name  = collider.gameObject.name.Substring(0, 7);
                Quaternion       rot          = collider.gameObject.transform.rotation;
                PowerupBehaviour pb           = collider.gameObject.GetComponent <PlayerController>().powerup;
                GameObject       player_clone = PhotonNetwork.Instantiate(player_name, new Vector3(
                                                                              collider.gameObject.transform.position.x,
                                                                              collider.gameObject.transform.position.y,
                                                                              -collider.gameObject.transform.position.z),
                                                                          rot);
                reconstruction(player_clone, pb, collider, old_cmd,
                               old_cn, old_tn);
            }
        }
        else if (collider.tag == "Ghost" && Connector.is_host == 1)
        {
            Vector3 diff = collider.gameObject.transform.position - this.transform.position;
            if (x_warp_node && Mathf.Abs(diff.x) > 1.0f)
            {
                string     ghost_name  = collider.gameObject.name.Substring(0, 6);
                GameObject ghost_clone = PhotonNetwork.Instantiate(ghost_name, new Vector3(
                                                                       -collider.gameObject.transform.position.x,
                                                                       collider.gameObject.transform.position.y,
                                                                       collider.gameObject.transform.position.z),
                                                                   Quaternion.identity);

                ghost_clone.GetComponent <GhostMovement>().traversal_nodes = collider.GetComponent <GhostMovement>().traversal_nodes;
                ghost_clone.GetComponent <GhostMovement>().npc_no          = collider.GetComponent <GhostMovement>().npc_no;
                PhotonNetwork.Destroy(collider.gameObject);
            }
            if (z_warp_node && Mathf.Abs(diff.z) > 1.0f)
            {
                string     ghost_name  = collider.gameObject.name.Substring(0, 6);
                Quaternion rot         = collider.gameObject.transform.rotation;
                GameObject ghost_clone = PhotonNetwork.Instantiate(ghost_name, new Vector3(
                                                                       collider.gameObject.transform.position.x,
                                                                       collider.gameObject.transform.position.y,
                                                                       -collider.gameObject.transform.position.z),
                                                                   Quaternion.identity);
                ghost_clone.GetComponent <GhostMovement>().traversal_nodes = collider.GetComponent <GhostMovement>().traversal_nodes;
                ghost_clone.GetComponent <GhostMovement>().npc_no          = collider.GetComponent <GhostMovement>().npc_no;
                PhotonNetwork.Destroy(collider.gameObject);
            }
        }
    }