Inheritance: MonoBehaviour
Exemplo n.º 1
0
    void OnNetworkInstantiate(NetworkMessageInfo msg)
    {
        // I like to setup a local variable to our local gameObject so the code is a little more readable
        GameObject localplayer = this.gameObject;

        networkView.group = 1;         // send all RPC messages for group 1, so only the player instantiate is on group 0


        if (networkView.isMine)
        {
            // On the original player since we control the player with the keyboard controls
            // so we don't want to use the NetworkRigidbody script which was specific for the prediction and smoothing
            // of remote networked character avatars.  Therefore, let's find that component on the new player and
            // disable it
            //NetworkRigidbody _NetworkRigidbody = (NetworkRigidbody) localplayer.GetComponent("NetworkRigidbody");
            //_NetworkRigidbody.enabled = false;

            AudioListener al = (AudioListener)localplayer.GetComponentInChildren(typeof(AudioListener));
            al.enabled = true;
        }
        else
        {
            name += "Remote";

            // Since this player object is a remote avatar, we wont be performing any manual controls to this avatar.
            // Instead we want all updates to come from network updates.  The NetworkView will send those updates
            // automatically.  Therefore we want to enable "NetworkRigidbody" component which will process all
            // the prediction and smoothing for our avatar
            NetworkRigidbody _NetworkRigidbody = (NetworkRigidbody)localplayer.GetComponent("NetworkRigidbody");
            _NetworkRigidbody.enabled = true;
        }
        //*/
    }
Exemplo n.º 2
0
 private void Awake()
 {
     _networkRigidbody = GetComponent <NetworkRigidbody>();
     _boxCollider      = GetComponent <BoxCollider>();
     _sphereCollider   = GetComponent <SphereCollider>();
     _time             = Time.time + 2f;
 }
Exemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     rb            = GetComponent <Rigidbody>();
     networkRb     = GetComponent <NetworkRigidbody>();
     currentHealth = 100f;
     maximumHealth = 100f;
 }
Exemplo n.º 4
0
    void OnNetworkInstantiate(NetworkMessageInfo msg)
    {
        //netPlayer = msg.sender;
        netPlayer = networkView.owner;
        NetworkConnection.GetInst().playerObjMap.Add(netPlayer, this);

        // This is our own player
        if (networkView.isMine)
        {
            Camera.main.SendMessage("SetTarget", transform);
            NetworkRigidbody comp = GetComponent("NetworkRigidbody") as NetworkRigidbody;
            comp.enabled = false;
        }
        // This is just some remote controlled player, don't execute direct
        // user input on this
        else
        {
            name += "Remote";
            CarController cc = GetComponent("CarController") as CarController;
            cc.enabled = false;
            NetworkRigidbody comp = GetComponent("NetworkRigidbody") as NetworkRigidbody;
            comp.enabled = true;
            Camera cam = GetComponentInChildren <Camera>();
            if (cam != null)
            {
                cam.enabled = false;
            }
            Camera.main.SendMessage("ApplyCameraSetting");
        }
    }
Exemplo n.º 5
0
 public void Awake()
 {
     _cooldown    = 2;
     _networkBody = GetComponent <NetworkRigidbody>();
     _UI_cooldown = GUI_Controller.Current.Skill;
     _UI_cooldown.InitView(_abilityInterval);
     _cost = 1;
 }
Exemplo n.º 6
0
    /// <summary>
    /// Fire the weapon.
    /// </summary>

    public override void Fire()
    {
        if (!mIsPlayerControlled || !canFire)
        {
            return;
        }

        float remainder = generator.DrainPower(firedObject.energyCost);

        if (remainder > 0f)
        {
            Debug.Log("TODO: Some kind of 'out of power' message");
            return;
        }

        mNextFire = Time.time + firedObject.firingFrequency;

        // Instantiate a new object
        GameObject go = NetworkManager.RemoteInstantiate(prefab, mTrans.position, mTrans.rotation);

        // The weapon's initial velocity should match the launcher's
        if (go != null)
        {
            if (mCollidersToIgnore != null)
            {
                FiredObject fo = go.GetComponent <FiredObject>();
                if (fo != null)
                {
                    fo.ignoreColliders = mCollidersToIgnore;
                }
            }

            NetworkRigidbody nrb = go.GetComponent <NetworkRigidbody>();

            if (nrb != null)
            {
                if (mRb != null)
                {
                    nrb.SetVelocity(mRb.velocity + mTrans.rotation * (Vector3.forward * (firedObject.firingVelocity / 3.6f)));
                }
                else
                {
                    nrb.SetVelocity(mTrans.rotation * (Vector3.forward * (firedObject.firingVelocity / 3.6f)));
                }
            }
            else
            {
                Debug.LogError("No " + typeof(NetworkRigidbody) + " found on " + Tools.GetHierarchy(go));
            }

            // Any additional functionality
            OnFire(go);
        }
    }
Exemplo n.º 7
0
    /// <summary>
    /// When the plasma beam hits something we want to apply damage and destroy the beam.
    /// </summary>

    void OnTriggerEnter(Collider col)
    {
        if (!mIsMine)
        {
            return;
        }

        Rigidbody rb = Tools.FindInParents <Rigidbody>(col.transform);

        if (rb != null)
        {
            Explosive exp = rb.GetComponentInChildren <Explosive>();

            if (exp != null)
            {
                exp.Explode();
            }
            else
            {
                Rigidbody myRb = rigidbody;

                if (myRb != null)
                {
                    Vector3 force = myRb.velocity * myRb.mass * forceOnCollision;
                    Vector3 pos   = transform.position;

                    NetworkRigidbody nrb = NetworkRigidbody.Find(rb);
                    if (nrb != null)
                    {
                        nrb.AddForceAtPosition(force, pos);
                    }
                }
            }
        }

        // Apply damage to the unit, if we hit one
        GameUnit unit = Tools.FindInParents <GameUnit>(col.transform);

        if (unit != null)
        {
            unit.ApplyDamage(damageOnHit);
        }

        // Destroy this beam
        NetworkManager.RemoteDestroy(gameObject);
    }
Exemplo n.º 8
0
    /// <summary>
    /// Explode the explosive, adding an explosion force and creating an explosion prefab.
    /// </summary>

    public void Explode()
    {
        if (mIsMine)
        {
            Rigidbody myRigidbody = rigidbody;
            Vector3   pos         = transform.position;

            // Get a list of colliders caught int he blast
            Collider[] cols = Physics.OverlapSphere(pos, radius);

            // Convert the list of colliders into a list of rigidbodies
            List <Rigidbody> rbs = Tools.GetRigidbodies(cols);

            // Apply the explosion force to all rigidbodies caught in the blast
            foreach (Rigidbody rb in rbs)
            {
                if (rb != myRigidbody)
                {
                    // TODO: Apply damage here
                    NetworkRigidbody nrb = NetworkRigidbody.Find(rb);
                    if (nrb != null)
                    {
                        nrb.AddExplosionForce(force, pos, radius, 0f);
                    }
                }
            }

            // Instantiate an explosion prefab
            if (explosionPrefab != null)
            {
                NetworkManager.RemoteInstantiate(explosionPrefab, pos,
                                                 Quaternion.identity, NetworkManager.gameChannel);
            }

            // Destroy this game object
            NetworkManager.RemoteDestroy(gameObject);
        }
    }
Exemplo n.º 9
0
    void OnNetworkInstantiate(NetworkMessageInfo msg)
    {
        // I like to setup a local variable to our local gameObject so the code is a little more readable
        GameObject localplayer = this.gameObject;

        //networkView.group = 1; // send all RPC messages for group 1, so only the player instantiate is on group 0

        /* If the player being spawned is ME, then I need to enable a whole bunch of attached components I initally disabled because I didn't want them
         * enabled for remote players, just myself, so I'm doing that now */
        if (networkView.isMine)
        {
            // On the original player since we control the player with the keyboard controls
            // so we don't want to use the NetworkRigidbody script which was specific for the prediction and smoothing
            // of remote networked character avatars.  Therefore, let's find that component on the new player and
            // disable it
            NetworkRigidbody _NetworkRigidbody = (NetworkRigidbody)localplayer.GetComponent("NetworkRigidbody");
            _NetworkRigidbody.enabled = false;

            // Since this is the local player and not the remote avatar we do want to ensure the player controls
            // are active.
            CharacterController cc = (CharacterController)localplayer.GetComponent <CharacterController>();
            cc.enabled = true;

            CharacterMotor cm = (CharacterMotor)localplayer.GetComponent <CharacterMotor>();
            cm.enabled = true;

//			AudioSource source = (AudioSource)localplayer.GetComponent<AudioSource>();
//			source.enabled = true;
//
            // We don't have a Temp Camera setup in the scene, but if we did we would need to disable before activating
            // the players camera
            //GameObject.Find("TempCamera").SetActiveRecursively(false);

            // Since this is the local player, we want our local player camera enabled as the main camera for the scene
            // Since the camera component is in a sub object called Main Camera under the Player Prefab we can use
            // GetComponentInChildren looking specifically for our "Camera" component. There should only be one, so we
            // don't need to loop through multiple components
            Camera ca = (Camera)localplayer.GetComponentInChildren(typeof(Camera));
            ca.enabled = true;             // activate our camera

            // Since this is the local player, we want our local player audio enabled. Since you can only have one audio
            // enabled in a scene, we need to make sure it's not enabled for remote avatars.  Therefore we set it disabled
            // be default and enable it when we spawn the player
            AudioListener al = (AudioListener)localplayer.GetComponentInChildren(typeof(AudioListener));
            al.enabled = true;

            VoiceChatGUI vcg = (VoiceChatGUI)localplayer.GetComponent <VoiceChatGUI>();
            vcg.enabled = true;

            TextEditorGUI teg = (TextEditorGUI)localplayer.GetComponent <TextEditorGUI>();
            teg.enabled = true;
        }

        /* If the networkView isn't mine, then the player being spawned is some remote player so we'll enable their NetworkRigidBody component.
         * We'll also disable their CharacterController because otherwise we'd be able to control them!!
         */
        else
        {
            Debug.Log("NetworkView is Remote");
            Debug.Log("Remote NetworkView.owner = " + networkView.owner);
            name += "Remote";

            // Since this player object is a remote avatar, we wont be performing any manual controls to this avatar.
            // Instead we want all updates to come from network updates.  The NetworkView will send those updates
            // automatically.  Therefore we want to enable "NetworkRigidbody" component which will process all
            // the prediction and smoothing for our avatar
            NetworkRigidbody _NetworkRigidbody = (NetworkRigidbody)localplayer.GetComponent("NetworkRigidbody");
            _NetworkRigidbody.enabled = true;

            // Since this is a player avatar for a remote player, we need to make sure its camera is disabled.  We already
            // have our local player camera so we don't need this one
            CharacterController cc = (CharacterController)localplayer.GetComponent("CharacterController");
            cc.enabled = false;
        }
    }
Exemplo n.º 10
0
 void Awake()
 {
     //if(!networkView.isMine)
     //{
     //	enabled = false;
     //}else{
         myTransform = transform;
         destinationPosition = myTransform.position;
         animator = transform.GetComponent<Animator>();
         if(animator.layerCount >= 2)
             animator.SetLayerWeight(1,1);
         if(this.gameObject.tag == "Player") //set the Player to the default controller at game start
             isActive = true;
         networkSync = transform.GetComponent<NetworkRigidbody>();
         //Hash Animation names for Performance
         locomotionID = Animator.StringToHash("Base Layer.Locomotion");
     //}
 }
Exemplo n.º 11
0
 void Awake()
 {
     if(!networkView.isMine)
     {
         enabled = false;
     }else{
         destinationPosition = transform.position;
         animator = transform.GetComponent<Animator>();
         nAgent = transform.GetComponent<NavMeshAgent>();
         if(animator.layerCount >= 2)
             animator.SetLayerWeight(1,1);
         if(this.gameObject.tag == "Player") //set the Player to the default controller at game start
             isActive = true;
         networkSync = transform.GetComponent<NetworkRigidbody>();
         //curAbility = abilityList[0];
     }
 }
Exemplo n.º 12
0
 private void Awake()
 {
     _networkRigidbody = GetComponent <NetworkRigidbody>();
 }