// Update is called once per frame void FixedUpdate() { if (bullet == null && Input.GetButton("Fire1") && myrenderer.isVisible) { Vector3 position = new Vector3( gameObject.transform.position.x + controller.direction.x * asciiMap.CharacterWidth, gameObject.transform.position.y + controller.direction.y * asciiMap.CharacterHeight, gameObject.transform.position.z); GameObject prefab = (GameObject)Instantiate(prefabBullet, position, Quaternion.identity, prefabParent.transform); bullet = prefab.GetComponent <FireableObject> (); bullet.Fire(controller.direction); } }
// Update is called once per frame void FixedUpdate() { float currentTime = Time.time; if (currentTime - lastFireTime > (FireSpeed) && bullet == null && Input.GetButton("Fire1") && myrenderer.isVisible) { float characterWidth = asciiMap.characterWidth; float characterHeight = asciiMap.characterHeight; direction = new Vector3(controller.direction.x, controller.direction.y, 0); if (direction.x > 0) { direction.x = 1; } else if (direction.x < 0) { direction.x = -1; } if (direction.y > 0) { direction.y = 1; } else if (direction.y < 0) { direction.y = -1; } Vector3 fireableStartPosition = new Vector3(gameObject.transform.position.x + (direction.x * characterWidth), gameObject.transform.position.y + (direction.y * characterHeight), 0); GameObject prefab = (GameObject)Instantiate(prefabBullet, fireableStartPosition, Quaternion.identity, prefabParent.transform); bullet = prefab.GetComponent <FireableObject> (); bullet.Fire(direction); //if (!audio.isPlaying) { aaudio.PlayOneShot(fireSound, 0.1F); //} lastFireTime = Time.time; if (colorChange != null) { colorChange.Restart(); } } // make sure the audio stops if the bullet stops if (bullet == null && aaudio.isPlaying) { aaudio.Stop(); } }