void Update() { //check if some weapons are available if (Input.GetButton("Fire1") && this.GetComponent <PlayerObjectInteraction> ().InProximityObject.Count > 0) { PlayerObjectInteraction playerObjectInteraction = this.gameObject.GetComponent <PlayerObjectInteraction> (); //remove old weapon if (playerObjectInteraction.currentGameObject != null) { playerObjectInteraction.currentGameObject.transform.parent = null; } //set weapon type GameObject PickUpObject = playerObjectInteraction.InProximityObject[0]; interaction = PickUpObject.GetComponent <ObjectPropreties> ().ObjectType.UseObject; //get new object interaction function playerObjectInteraction.useObject = interaction; //set new object interaction function //set visual weapon playerObjectInteraction.currentGameObject = PickUpObject; PickUpObject.transform.position = this.transform.position - new Vector3(0, 0.1f, 0); PickUpObject.transform.parent = this.transform; } }
// PRIVATE API private void destroySelf() { PlayerObjectInteraction.removePickableObject(this.gameObject); Instantiate(destroyedVersion, transform.position, transform.rotation); this.tag = "Untagged"; Destroy(this.gameObject); }
private void FindOtherPlayer() { if (otherPlayer == null) { int otherPlayerID = playerID == 1 ? 2 : 1; otherPlayer = GameObject.Find("Player " + otherPlayerID).GetComponent <PlayerObjectInteraction>(); } }
private void spawnLoot() { loot.name = "The Loot"; Debug.Log("Loot tag is " + loot.tag); Vector3 lootPosition = transform.position; lootPosition.y += 0.2f; Instantiate(loot, lootPosition, transform.rotation); PlayerObjectInteraction.newPickableObject(loot); }
private bool player2Host; // Player 2 in host private void Start() { player1Host = isServer && isLocalPlayer; player1Client = !isServer && !isLocalPlayer; player2Client = !isServer && isLocalPlayer; player2Host = isServer && !isLocalPlayer; PlayerMove playerMove = GetComponent <PlayerMove>(); PlayerObjectInteraction playerObjectInteraction = GetComponent <PlayerObjectInteraction>(); if (player1Host || player1Client) { gameObject.name = "Player 1"; // Additional setup not needed since player 1 is default on prefab Destroy(player2Model); } else if (player2Host || player2Client) { gameObject.name = "Player 2"; playerMove.PlayerID = 2; playerObjectInteraction.dropBox.transform.Translate(new Vector3(0, 0, clientExtraDropGap)); Destroy(player1Model); player2Model.SetActive(true); playerMove.animator = player2Model.GetComponent <Animator>(); playerObjectInteraction.animator = player2Model.GetComponent <Animator>(); int player2Layer = LayerMask.NameToLayer("Player 2"); gameObject.layer = player2Layer; foreach (Transform child in transform) { child.gameObject.layer = player2Layer; } } else { Debug.LogError("Invalid player added through networking"); } if (isLocalPlayer) { GManager.Instance.RegisterOriginalPlayerResettableObject(transform.position, transform.rotation); } if (!isServer) { GetComponent <PlayerGameManagerCommunicators>().CmdStartGameManagers(); } }
//respawn object, or destroy it and create the SpawnOnDeath objects private void Death() { //player drop item if (tag == "Player") { playerObjectInteraction = GetComponent <PlayerObjectInteraction>(); } if (playerObjectInteraction && playerObjectInteraction.holdingObject) { playerObjectInteraction.AccidentallyLetGoOfPickup(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; if (respawn) { var rigid = GetComponent <Rigidbody>(); if (rigid) { rigid.velocity *= 0; } transform.position = respawnPos; dead = false; currentHealth = defHealth; } else { Destroy(gameObject); } if (spawnOnDeath.Length == 0) { return; } foreach (var obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } }
// Update is called once per frame void Update() { currentUpdateFunction(); if (Input.GetKeyDown(KeyCode.Space)) { playerInteraction(transform.position.x); } if (Input.GetKeyDown(KeyCode.C)) { objectInteraction = ChangeColor; } if (Input.GetKeyDown(KeyCode.V)) { objectInteraction = DrawChangeColor; } else if (Input.GetKeyDown(KeyCode.B)) { objectInteraction = DoNothing; } }
//respawn object, or destroy it and create the SpawnOnDeath objects void Death() { //player drop item if (tag == "Player") { throwing = GetComponent <PlayerObjectInteraction>(); } if (throwing && throwing.heldObj && throwing.heldObj.tag == "Pickup") { throwing.ThrowPickup(); } if (deadSound) { AudioSource.PlayClipAtPoint(deadSound, transform.position); } flashing = false; flashObject.GetComponent <Renderer>().material.color = originalColor; if (respawn) { if (GetComponent <Rigidbody>()) { GetComponent <Rigidbody>().velocity *= 0; } transform.position = respawnPos; dead = false; currentHealth = defHealth; } else { Destroy(gameObject); } if (spawnOnDeath.Length != 0) { foreach (GameObject obj in spawnOnDeath) { Instantiate(obj, transform.position, Quaternion.Euler(Vector3.zero)); } } }
private void OnTriggerStay(Collider other) { if (other.tag == "Player") { // Do nothing if not local player if (!other.GetComponent <UnityEngine.Networking.NetworkIdentity>().isLocalPlayer) { return; } // Deactivate camera follow cameraFollow = Camera.main.GetComponent <CameraFollow>(); cameraFollow.enabled = false; cameraDeactivated = true; cameraFollowTime = other.GetComponent <PlayerMove>().cameraDelayTimerBeforeRespawn; PlayerObjectInteraction playerObjectInteraction = other.GetComponent <PlayerObjectInteraction>(); // Reset held object if carrying if (playerObjectInteraction.newHeldObj != PlayerObjectInteraction.HoldableType.None) { if (playerObjectInteraction.newHeldObj == PlayerObjectInteraction.HoldableType.Pushable) { other.GetComponent <PlayerMove>().IsGrabingPushable = false; other.GetComponent <PlayerMove>().rotateSpeed = playerObjectInteraction.defaultRotateSpeed; } // Drop a cached object into the deadzone! if (playerObjectInteraction.HeldObjType != PickupableObject.PickupableType.BigBox) { playerObjectInteraction.DropPickup(); } else { playerObjectInteraction.LetGoOfPushable(); } } } }
// Use this for initialization void Start() { currentUpdateFunction = BasicMovement; playerInteraction = GimmeTwo; objectInteraction = DoNothing; }