// Use this for initialization protected override void Start() { base.Start(); target = transform.Find("Target"); targetArm = target.gameObject.GetComponent <SpringArm>(); gun = transform.Find("Gun"); canon = gun.Find("Canon"); enemyTarget = new List <Transform>(); canShoot = true; targetArm.setUseRotationLimits(false, false, false); //switch that determines the initial orientation of the turret switch (_orientation) { case orientation.North: targetArm.addRotation(0, 180, 0); targetArm.setMinLimits(-30, 150, 0); targetArm.setMaxLimits(30, 210, 0); targetArm.setUseRotationLimits(true, true, true); break; case orientation.West: targetArm.addRotation(0, 90, 0); targetArm.setMinLimits(-30, 60, 0); targetArm.setMaxLimits(30, 120, 0); targetArm.setUseRotationLimits(true, true, true); break; case orientation.South: targetArm.setMinLimits(-30, -30, 0); targetArm.setMaxLimits(30, 30, 0); targetArm.setUseRotationLimits(true, true, true); break; case orientation.East: targetArm.addRotation(0, 270, 0); targetArm.setMinLimits(-30, 240, 0); targetArm.setMaxLimits(30, 300, 0); targetArm.setUseRotationLimits(true, true, true); break; } posses = canvas.transform.GetChild(0).Find("Posses").GetComponent <Button>(); if (gameMode is GameModeManager) { posses.onClick.AddListener((gameMode as GameModeManager).enableShootMode); } aimReticle = Instantiate(aimReticleObj, GameObject.Find("LocalUI").transform); aimReticle = aimReticle.transform.GetChild(0).gameObject; aimReticle.SetActive(false); }
/// <summary> /// Rotates the camera by the desired inputs. /// </summary> private void cameraRotation() { if (Input.GetButton("Fire2")) { camera.addRotation(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0); } }
//automatic gameplay #region /// <summary> /// Called once per update controls the activity of the turret. /// </summary> private void play() { if (isShooting) { if (enemyTarget.Count > 0) { Vector3 aux = enemyTarget[0].position - gun.position; float dirY = AngleDir(-target.forward, aux, target.up); float dirX = AngleDir(target.forward, aux, -target.right); targetArm.addRotation(dirX, dirY, 0); if (canShoot) { StartCoroutine(pressTrigger()); } } else { isShooting = false; } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Q)) { int index = cameras.IndexOf(currentTarget) + 1; if (index >= targetList.Count) { index = 0; } currentTarget = cameras[index]; camera.changeTarget(currentTarget); } if (cameras.IndexOf(currentTarget) > 0) { if (Input.GetKeyDown(KeyCode.Alpha1)) { camera.changeTarget(cameras[1]); currentTarget = cameras[1]; } if (Input.GetKeyDown(KeyCode.Alpha2)) { camera.changeTarget(cameras[2]); currentTarget = cameras[2]; } if (Input.GetKeyDown(KeyCode.Alpha3)) { camera.changeTarget(cameras[3]); currentTarget = cameras[3]; } if (Input.GetKeyDown(KeyCode.Alpha4)) { camera.changeTarget(cameras[4]); currentTarget = cameras[4]; } if (Input.GetKeyDown(KeyCode.Alpha5)) { camera.changeTarget(cameras[5]); currentTarget = cameras[5]; } if (Input.GetKeyDown(KeyCode.Alpha6)) { camera.changeTarget(cameras[6]); currentTarget = cameras[6]; } if (cameras.IndexOf(currentTarget) > cameras.Count - 3) { if (Input.GetKey(KeyCode.W)) { camera.addRotation(1, 0, 0); } if (Input.GetKey(KeyCode.S)) { camera.addRotation(-1, 0, 0); } if (Input.GetKey(KeyCode.D)) { camera.addRotation(0, -1, 0); } if (Input.GetKey(KeyCode.A)) { camera.addRotation(0, 1, 0); } } } }