示例#1
0
    public void gainFlag()
    {
        flag = GameObject.FindGameObjectWithTag("Flag");
        flag.GetComponent <Animator> ().SetBool("Wavin", true);
        Collider2D[] cols = flag.GetComponents <Collider2D> ();

        //deactivate rigidbody component
        Rigidbody2D rb = flag.GetComponent <Rigidbody2D> ();

        rb.gravityScale   = 0;
        rb.freezeRotation = false;
        rb.isKinematic    = true;

        flag.transform.parent = flagPos.transform;

        foreach (Collider2D coll in cols)
        {
            coll.enabled = false;
        }
        PhotonView flagPhotonView = flag.GetComponent <PhotonView> ();

        if (gameObject.GetPhotonView().isMine)
        {
            flagPhotonView.RequestOwnership();
        }
        flag.transform.localPosition = Vector3.zero;
        flag.transform.localRotation = Quaternion.Euler(Vector3.zero);

        if (PhotonNetwork.offlineMode)
        {
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            foreach (GameObject ply in players)
            {
                AILogic ailog = ply.GetComponent <AILogic> ();
                if (ailog)
                {
                    if (ply == this.gameObject)
                    {
                        ailog.StateChange(3);
                    }
                    else
                    {
                        ailog.StateChange(2);
                    }
                }
            }
        }
        isHandlingFlag = true;
        arrow.GetComponent <FixedRotation> ().isHandling = true;
    }
示例#2
0
    public void releasingFlag(int attackerID, float hurtForce)
    {
        //make Flag normal again

        if (flag && isHandlingFlag)
        {
            flag.GetComponent <Animator> ().SetBool("Wavin", false);

            if (attackerID != -5)
            {
                GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

                foreach (GameObject player in players)
                {
                    if (player.GetComponent <PhotonView> ().viewID == attackerID)
                    {
                        attacker = player;
                    }
                }
            }
            else
            {
                attacker = gameObject;
            }
            Rigidbody2D rb = flag.GetComponent <Rigidbody2D> ();
            rb.gravityScale   = 1;
            rb.freezeRotation = true;
            rb.isKinematic    = false;
            Collider2D[] cols = flag.GetComponents <Collider2D> ();
            foreach (Collider2D coll in cols)
            {
                coll.enabled = true;
            }
            //apply force to flag;
            if (photonView.isMine)
            {
                photonView.RPC("NullParent", PhotonTargets.Others);
                flag.transform.parent = null;
            }
            if (flag.GetComponent <PhotonView> ().isMine)
            {
                Vector3 hurtVector = (transform.position - attacker.transform.position) / 2 + Vector3.up * 7f;

                flag.GetComponent <Rigidbody2D> ().AddForce(hurtVector * hurtForce * 10);
            }

            //flag.GetComponent<PhotonView> ().RPC ("Taked", PhotonTargets.AllViaServer, false,0);
            //if (photonView.isMine) {
            //	arrow.SetActive (false);
            //}
            if (PhotonNetwork.offlineMode)
            {
                GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
                foreach (GameObject ply in players)
                {
                    AILogic ailog = ply.GetComponent <AILogic> ();
                    if (ailog)
                    {
                        ailog.StateChange(1);
                    }
                }
            }
            isHandlingFlag = false;
            arrow.GetComponent <FixedRotation> ().isHandling = false;

            PhotonNetwork.room.SetCustomProperties(expectedValue);
        }
    }