// Use this for initialization void Start() { boxCollider = GetComponent <BoxCollider>(); colliderAttack = boxCollider as Collider; colliderAttack.enabled = false; inputs = GetComponent <PlayerInputs>(); playerfov = GetComponent <PlayerFOV>(); animBody = GetComponent <Animator> (); }
// Start is called before the first frame update void Start() { fov = Instantiate(FOV, Vector3.zero, Quaternion.identity).GetComponent <PlayerFOV>(); fov.targetPlayer = transform; fov.SetOrigin(transform.position); }
// Update is called once per frame void Update() { if (canTeleport.teleport == true) { this.anim.Play("Idle"); canMove = false; } //Get list of targets from FieldOfView list targetsList = GetComponent <PlayerFOV>(); //transfer each target into local list visibleTargets.Clear(); foreach (Transform t in targetsList.visibleTargets) { visibleTargets.Add(t); } if (visibleTargets.Count == 0 || this.holding) { if (highlightTarget) { highlightTarget.gameObject.GetComponent <ItemScript>().highlightOff(); } highlightTarget = null; } if (!this.holding && visibleTargets.Count != 0 && visibleTargets[0] != highlightTarget) { if (highlightTarget) { highlightTarget.gameObject.GetComponent <ItemScript>().highlightOff(); } highlightTarget = visibleTargets[0]; Debug.Log("target switched: " + highlightTarget.gameObject.name); highlightTarget.gameObject.GetComponent <ItemScript>().highlightOn(); } if (Input.GetKeyDown("space") && !this.holdItem && visibleTargets.Count != 0) { this.holdItem = visibleTargets[0].gameObject; // Sets player to the pick-up item's parent so the item will move around with the player. //other.gameObject.transform.parent = this.transform; visibleTargets[0].gameObject.GetComponent <ItemScript>().playerRoot = this.transform; // mark the coin (or whatever object) as picked up visibleTargets[0].gameObject.GetComponent <ItemScript>().pickedUp = true; visibleTargets[0].gameObject.GetComponent <ItemScript>().thrown = false; // disable collision with held item Physics.IgnoreCollision(this.GetComponent <Collider>(), visibleTargets[0].gameObject.GetComponent <MeshCollider>(), true); this.wpArrow.SetActive(true); //other.gameObject.GetComponent<CoinScript>().pickedUp = true; StartCoroutine("PickUpCD"); } //checks to see if pressing any arrow keys //if so will go horizontal if left or right //will go vertical if up or down //transform.Translate(moveSpeed*Input.GetAxis("Horizontal")*Time.deltaTime, 0f, moveSpeed*Input.GetAxis("Vertical")*Time.deltaTime); //Debug.Log("islocalplayer "+isLocalPlayer); // creating normalizing direction so that movement isnt faster on diagonals if (canMove) { this.dir = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")).normalized; if (dir.sqrMagnitude > 0) { //Debug.Log(this.holdItem); // if Player is holding an item, then use the hold animation. if (this.holdItem) { this.anim.Play("Hold"); } else { this.anim.Play("Walk"); // play walking animation when moving this.holding = false; // if no holdItem, then holding must be false } this.transform.LookAt(transform.position + dir); // look in direction that player is walking controller.SimpleMove(this.moveSpeed * dir); //StartCoroutine("PlayWalkingNoise"); // Moved camera functionality to PlayerCamera.cs // camera.transform.position = new Vector3(this.transform.position.x, 21.5f, this.transform.position.z - 10); } else if (dir.sqrMagnitude == 0) { if (this.holdItem) { this.anim.Play("Hold-Idle"); } else { this.anim.Play("Idle"); // if not moving, play idle anim this.holding = false; // if no holdItem, then holding must be false } } } // Check if the player is invulnerable if (invulnerable) { if (invulnTime > 0) { invulnTime -= Time.deltaTime; } else { invulnerable = false; Physics.IgnoreCollision(gorillaCollider, GetComponent <Collider>(), false); invulnTime = 2; } } // code to drop items if (this.holding) { // if player is holding an item and presses space bar if (Input.GetKeyDown("space")) { // Debug.Log("drop"); // un-parent the player from the item //this.holdItem.transform.parent = null; // un-mark the coin as picked up. this.holdItem.GetComponent <ItemScript>().pickedUp = false; this.holdItem.GetComponent <ItemScript>().active = true; // set the item to active after being dropped // reenable collision Physics.IgnoreCollision(this.GetComponent <Collider>(), holdItem.gameObject.GetComponent <MeshCollider>(), false); //this.holdItem.GetComponent<CoinScript>().pickedUp = false; // get rid of hold item this.holdItem = null; this.wpArrow.SetActive(false); StartCoroutine("PickUpCD"); } // code to throw items else if (Input.GetKeyDown(KeyCode.LeftShift)) { // holding item + press left shift //this.holdItem.transform.parent = null; // unparent player from item this.holdItem.GetComponent <ItemScript>().pickedUp = false; this.holdItem.GetComponent <ItemScript>().active = true; // set the item to active after being dropped if (this.gameObject.name != "BatteryWithAnimations") { this.holdItem.GetComponent <Rigidbody>().velocity = (this.transform.forward * 20f + this.dir * 20f); // add velocity to thrown object <-- DOES NOT TAKE MASS INTO ACCOUNT //this.holdItem.GetComponent<Rigidbody>().AddForce(this.transform.forward * 20f - this.dir * 2, ForceMode.Impulse); // add force to thrown object <-- TAKES MASS INTO ACCOUNT //Debug.Log("throw"); this.holdItem.GetComponent <ItemScript>().thrown = true; this.holdItem.GetComponent <Rigidbody>().isKinematic = false; // set object to non-kinematic so it can be thrown } Physics.IgnoreCollision(this.GetComponent <Collider>(), holdItem.gameObject.GetComponent <MeshCollider>(), false); // get rid of hold item this.holdItem = null; this.wpArrow.SetActive(false); StartCoroutine("PickUpCD"); } } //if player isn't holding an item, reset to default speed if (!this.holding) { ChangeSpeed(defaultSpeed); } // Check if both oxygens are red. if (oxygen_color.text == "red" && oxygen2_color.text == "red") { if (oxygen > 0) { oxygen -= Time.deltaTime; } //If you update oxygen with a 0, the animation will play, otherwise it wont updateOxygen(0); // Check if one oxygen is red } else if (oxygen_color.text == "red" || oxygen2_color.text == "red") { if (oxygen > 0) { oxygen -= Time.deltaTime * 0.5f; } //If you update oxygen with a 0, the animation will play, otherwise it wont updateOxygen(0); } else { if (oxygen < 90) { oxygen += Time.deltaTime * 2; updateOxygen(1); } } }
// Update is called once per frame void Update() { if (canTeleport.teleport == true) { this.anim.Play("Idle"); canMove = false; } // creating normalizing direction so that movement isnt faster on diagonals if (canMove && isLocalPlayer) { //Get list of targets from FieldOfView list targetsList = GetComponent <PlayerFOV>(); //transfer each target into local list visibleTargets.Clear(); foreach (Transform t in targetsList.visibleTargets) { visibleTargets.Add(t); } if (visibleTargets.Count == 0 || this.holding) { if (highlightTarget) { highlightTarget.gameObject.GetComponent <ItemScript>().highlightOff(); } highlightTarget = null; } if (Input.GetKeyDown("space") && !this.holdItem && visibleTargets.Count != 0) { this.holdItem = visibleTargets[0].gameObject; // Sets player to the pick-up item's parent so the item will move around with the player. //other.gameObject.transform.parent = this.transform; visibleTargets[0].gameObject.GetComponent <ItemScript>().playerRoot = this.transform; // mark the coin (or whatever object) as picked up visibleTargets[0].gameObject.GetComponent <ItemScript>().pickedUp = true; visibleTargets[0].gameObject.GetComponent <ItemScript>().thrown = false; // disable collision with held item Physics.IgnoreCollision(this.GetComponent <Collider>(), visibleTargets[0].gameObject.GetComponent <MeshCollider>(), true); this.wpArrow.SetActive(true); //other.gameObject.GetComponent<CoinScript>().pickedUp = true; StartCoroutine("PickUpCD"); } this.dir = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical")).normalized; if (dir.sqrMagnitude > 0) { //Debug.Log(this.holdItem); // if Player is holding an item, then use the hold animation. if (this.holdItem) { this.anim.Play("Hold"); } else { this.anim.Play("Walk"); // play walking animation when moving this.holding = false; // if no holdItem, then holding must be false } this.transform.LookAt(transform.position + dir); // look in direction that player is walking controller.SimpleMove(this.moveSpeed * dir); //StartCoroutine("PlayWalkingNoise"); // Moved camera functionality to PlayerCamera.cs // camera.transform.position = new Vector3(this.transform.position.x, 21.5f, this.transform.position.z - 10); } else { if (this.holdItem) { this.anim.Play("Hold-Idle"); } else { this.anim.Play("Idle"); // if not moving, play idle anim this.holding = false; // if no holdItem, then holding must be false } } if (!this.holding && visibleTargets.Count != 0 && visibleTargets[0] != highlightTarget) { if (highlightTarget) { highlightTarget.gameObject.GetComponent <ItemScript>().highlightOff(); } highlightTarget = visibleTargets[0]; Debug.Log("target switched: " + highlightTarget.gameObject.name); highlightTarget.gameObject.GetComponent <ItemScript>().highlightOn(); } } // Check if both oxygens are red. if (oxygen_color.text == "red" && oxygen2_color.text == "red") { if (oxygen > 0) { oxygen -= Time.deltaTime; } //If you update oxygen with a 0, the animation will play, otherwise it wont updateOxygen(0); // Check if one oxygen is red } else if (oxygen_color.text == "red" || oxygen2_color.text == "red") { if (oxygen > 0) { oxygen -= Time.deltaTime * 0.5f; } //If you update oxygen with a 0, the animation will play, otherwise it wont updateOxygen(0); } else { if (oxygen < 90) { oxygen += Time.deltaTime * 2; updateOxygen(1); } } }