public void addWaterPack(bool isGold) { if (isGold) { if (!goldObj.getIsOwned()) { pbc.addBlaster(goldObj); hasGoldBlast = true; } } else { waterPacks++; waterPackText.text = "Water Packs: " + waterPacks; } questionScore++; }
void Update() { if (!gameOver) { //used to interact with objects RaycastHit interact; //used to see if a player is in the crosshairs RaycastHit playerFinder; crossHairWorldPos = cam.ScreenToWorldPoint(crossHairScreenPos); if (Physics.Raycast(crossHairWorldPos, transform.TransformDirection(Vector3.forward), out interact, interactLength)) { if (interact.collider.tag.Equals("item")) { isInteracting = true; if (hasPlayer) { pc.foundObject(); if (Input.GetMouseButtonDown(0)) { Blaster blaster = interact.collider.gameObject.GetComponent <Blaster>(); if (!blaster.getIsOwned() && blaster.getBlasterType() != 4) { pbc.addBlaster(blaster); } } } //if for some reason a PC isn't connected else { Debug.Log("No player controller attached"); } } else { isInteracting = false; } } else { isInteracting = false; } // Does the ray intersect any objects excluding the player layer if (Physics.Raycast(crossHairWorldPos, transform.TransformDirection(Vector3.forward), out playerFinder, gunDist, layerMask)) { if (playerFinder.collider.tag.Equals("Player")) { if (playerFinder.collider.GetComponent <playerController>().checkIfRedTeam() != pc.checkIfRedTeam()) { foundPlayer = true; if (hasPlayer) { pc.foundPlayer(); } //In a perfect world, this line never runs else { Debug.Log("No player controller attached"); } } } else if (playerFinder.collider.tag.Equals("AI")) { if (playerFinder.collider.GetComponent <aiPlayerController>().checkIfRedTeam() != pc.checkIfRedTeam()) { foundPlayer = true; if (hasPlayer) { pc.foundPlayer(); } else { Debug.Log("No player controller attached"); } } } else { foundPlayer = false; } //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); //Debug.Log("Did Hit"); } else { foundPlayer = false; } if (!isInteracting && !foundPlayer) { if (hasPlayer) { if (pc.isCrossHairChanged()) { pc.foundNothing(); } } else { //Debug.Log("No player controller attached"); } } //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 15, Color.yellow); if (gc == null) { // Debug.Log("Null gc"); gc = parent.GetComponentInChildren <GameController>(); if (gc == null) { //Debug.Log("Could not locate GameController"); } } else { if (!gc.getQuestionMode()) { if (axes == RotationAxes.MouseXAndY) { rotAverageY = 0f; rotAverageX = 0f; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotationX += Input.GetAxis("Mouse X") * sensitivityX; //rotationX = ClampAngle(rotationX, minimumX, maximumX); rotationY = ClampAngle(rotationY, minimumY, maximumY); rotArrayY.Add(rotationY); rotArrayX.Add(rotationX); if (rotArrayY.Count >= frameCounter) { rotArrayY.RemoveAt(0); } if (rotArrayX.Count >= frameCounter) { rotArrayX.RemoveAt(0); } for (int j = 0; j < rotArrayY.Count; j++) { rotAverageY += rotArrayY[j]; } for (int i = 0; i < rotArrayX.Count; i++) { rotAverageX += rotArrayX[i]; } rotAverageY /= rotArrayY.Count; rotAverageX /= rotArrayX.Count; rotAverageY = ClampAngle(rotAverageY, minimumY, maximumY); //rotAverageX = ClampAngle(rotAverageX, minimumX, maximumX); Quaternion yQuaternion = Quaternion.AngleAxis(rotAverageY, Vector3.left); Quaternion xQuaternion = Quaternion.AngleAxis(rotAverageX, Vector3.up); //Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left); //Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up); transform.localRotation = originalRotation * yQuaternion; parent.transform.localRotation = originalRotation * xQuaternion; } else if (axes == RotationAxes.MouseX) { rotAverageX = 0f; rotationX += Input.GetAxis("Mouse X") * sensitivityX; rotArrayX.Add(rotationX); if (rotArrayX.Count >= frameCounter) { rotArrayX.RemoveAt(0); } for (int i = 0; i < rotArrayX.Count; i++) { rotAverageX += rotArrayX[i]; } rotAverageX /= rotArrayX.Count; //rotAverageX = ClampAngle(rotAverageX, minimumX, maximumX); Quaternion xQuaternion = Quaternion.AngleAxis(rotAverageX, Vector3.up); transform.localRotation = originalRotation * xQuaternion; } else { rotAverageY = 0f; rotationY += Input.GetAxis("Mouse Y") * sensitivityY; rotArrayY.Add(rotationY); if (rotArrayY.Count >= frameCounter) { rotArrayY.RemoveAt(0); } for (int j = 0; j < rotArrayY.Count; j++) { rotAverageY += rotArrayY[j]; } rotAverageY /= rotArrayY.Count; rotAverageY = ClampAngle(rotAverageY, minimumY, maximumY); Quaternion yQuaternion = Quaternion.AngleAxis(rotAverageY, Vector3.left); transform.localRotation = originalRotation * yQuaternion; } } } } }
void Update() { if (gameStarted) { if (!dead) { //if has a gun, find player or nearby guns as long as not chasing a player if (ownsBlaster) { //If you don't currently have a target, check once every ___ frames if (!hasTarget) { targetCheck++; if (targetCheck == TARGET_CHECK_FRAME_COUNT) { targetCheck = 0; float distance = 500f; float tempDist; int foundIndex = 0; for (int i = 0; i < touchingPlayers.Count; i++) { if (touchingPlayers[i].tag.Equals("Player") || touchingPlayers[i].tag.Equals("AI")) { tempDist = Vector3.Distance(transform.position, touchingPlayers[i].transform.position); if (tempDist < distance) { distance = tempDist; foundIndex = i; hasPlayer = true; hasTarget = true; } } } //keep following that player unless another one comes closer if (hasPlayer && hasTarget) { targetObj = touchingPlayers[foundIndex]; targetPoint = touchingPlayers[foundIndex].transform.position; apc.setTarget(targetObj, true); } //if no players are contained in the area else { if (Vector3.Distance(targetPoint, parent.transform.position) < 25f) { int rand = Random.Range(0, runPoints.Length); targetPoint = runPoints[rand]; //Debug.Log("Running to center"); //if close to the origin point, run away in a direction //if (transform.position.sqrMagnitude < 500f) //{ //Debug.Log("Running away from the center"); //runToCenter = false; //} } //check if far away from origin and return if so //else //{ // if (transform.position.sqrMagnitude > 80000f) // { // //Debug.Log("Going back to old Nassau"); // runToCenter = true; // targetPoint = Vector3.zero; // } //} } } } //if you have a target, lock on to it's position, //if it's a player and they're in range and you can shoot //blast 'em else { playerTargetCheck++; if (playerTargetCheck == PLAYER_TARGET_FRAME_COUNT) { playerTargetCheck = 0; targetPoint = targetObj.transform.position; //if targeting player if (hasPlayer) { if (Vector3.Distance(targetPoint, transform.position) <= gunDist) { if (!shooting) { shooting = true; } } else { shooting = false; } if ((Vector3.Distance(targetPoint, transform.position) <= gunDist) && abc.canShoot()) { questionReloading = false; //if you want the effect instantiated at a point if (abc.getBlasterType() == 1) { shoot1(abc.getName() + "effect", abc.getDamage(), targetObj); abc.incrementAmmo(); abc.shooting(); apc.setShooting(true); } //if you want a trail to be shot if (abc.getBlasterType() == 2 || abc.getBlasterType() == 3) { shoot2(abc.getName() + "effect", abc.getDamage(), abc.getGunTipPosition(), targetObj); abc.incrementAmmo(); abc.shooting(); apc.setShooting(true); } } else { if (!abc.isShooting()) { apc.setShooting(false); } if (!abc.hasAmmo() && !questionReloading) { abc.startAnswerFakeQuestion(); questionReloading = true; } //if out of your gun's range, pursue but act as if you don't have a player target //to prevent shooting if ((Vector3.Distance(targetPoint, transform.position) > gunDist)) { hasPlayer = false; } } } } } } //if you don't have a gun, priority number one is finding one. Advance towards //the origin else { //Are we already chasing a gun? if (hasBlaster) { if (targetBlaster.getIsOwned()) { hasBlaster = false; hasTarget = false; int rand = Random.Range(0, runPoints.Length); targetPoint = runPoints[rand]; } } //we don't have a gun and we aren't chasing one. Is one contained in //our collider? else { //Check if we have a blaster in our current list of contained objs //made float really high so it is larger than the distance to an item float distance = 500f; float tempDist; int foundIndex = 0; for (int i = 0; i < touchingObjs.Count; i++) { tempDist = Vector3.Distance(transform.position, touchingObjs[i].transform.position); if (tempDist < distance) { distance = tempDist; foundIndex = i; hasBlaster = true; hasTarget = true; } } //Checks if a blaster has been successfully located //if so, update travel location if (hasBlaster && hasTarget) { targetObj = touchingObjs[foundIndex]; targetPoint = targetObj.transform.position; targetBlaster = targetObj.GetComponent <Blaster>(); apc.setTarget(targetObj, false); } //if moving towards the center and not within 10 ft, else { if (Vector3.Distance(targetPoint, parent.transform.position) < 25f) { int rand = Random.Range(0, runPoints.Length); targetPoint = runPoints[rand]; } } } } } } else { if (countdown) { if (PhotonNetwork.Time > gameTimer) { countdown = false; gameStarted = true; int rand = Random.Range(0, runPoints.Length); targetPoint = runPoints[rand]; Debug.Log("target point set"); } } } }