void FixedUpdate() { if (!GlobalFlags.getPaused()) { GameObject cannon = GameObject.FindGameObjectWithTag("Player"); if (Input.GetMouseButton(0)) { Plane playerPlane = new Plane(Vector3.forward, transform.position); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); float hitdist = 0; if (playerPlane.Raycast(ray, out hitdist)) { Vector3 target = ray.GetPoint(hitdist); float mouseDist = Vector3.Distance(transform.position, target); float cannonDist = Vector3.Distance(transform.position, cannon.transform.position); if (mouseDist < cannonDist - sizeOffset) { if (GlobalFlags.trianglesStatic) { GlobalFlags.canFire = true; GlobalFlags.bandAidFixToDefeatAllOtherBandAidFixes = true; } float y = (target.y - cannon.transform.position.y); float x = (target.x - cannon.transform.position.x); float atan = Mathf.Atan2(y, x); cannon.transform.rotation = Quaternion.Euler(new Vector3(0, 0, atan * Mathf.Rad2Deg - 90)); } else if (Vector3.Distance(target, cannon.transform.position) < moveOffset) { GlobalFlags.canFire = false; float y = (target.y - transform.position.y); float x = (target.x - transform.position.x); float atan = Mathf.Atan2(y, x); transform.rotation = Quaternion.Euler(new Vector3(0, 0, atan * Mathf.Rad2Deg - 90)); } } } } }
// Update is called once per frame void Update() { if (!GlobalFlags.getPaused()) { GameObject cannon = GameObject.FindGameObjectWithTag("Player"); if (Input.GetMouseButtonUp(0) && GlobalFlags.canFire) { GameObject triInstance = queueScript.fireShot(); //getting the triangle from the queue, so the queue can update queueScript.randomLevelQueue(); if (triInstance != null) { GameObject gObject = GameObject.FindGameObjectWithTag("Music"); Music music = gObject.GetComponent <Music>(); if (GlobalFlags.getMusicVolume() > 0.1f) { music.audio.volume = 0.1f; } music.playSoundEffect("pterodactyl"); music.setSeStartTime(Time.time, 3); triInstance.transform.localPosition = shooter.transform.position + ((shooter.transform.rotation * Vector3.up) * 0.3f); triInstance.transform.localRotation = Quaternion.identity; triInstance.rigidbody.AddForce((shooter.transform.rotation * Vector3.up) * shootingForce); Vector3 rot = transform.rotation.eulerAngles; rot.z -= 60; triInstance.transform.rotation = Quaternion.Euler(rot); cannon.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, 180)); if (GlobalFlags.bandAidFixToDefeatAllOtherBandAidFixes) { GlobalFlags.canFire = false; GlobalFlags.trianglesStatic = false; } } } } }