/* Spawn Ammo/Weapon for Player*/ public void Shoot() { foreach (Transform T in transform) { AmmoManager.SpawnAmmo(T.position, T.rotation, this); } }
void FixedUpdate() { float horizontal = Input.GetAxis(horizontalAxis); float vertical = Input.GetAxis(verticalAxis); Vector3 direction = new Vector3(horizontal, 0, vertical); theBody.AddForce(direction.normalized * maxSpeed); theBody.velocity = new Vector3( Mathf.Clamp(theBody.velocity.x, -maxSpeed, maxSpeed), Mathf.Clamp(theBody.velocity.y, -maxSpeed, maxSpeed), Mathf.Clamp(theBody.velocity.z, -maxSpeed, maxSpeed)); if (mouseLook) { Vector3 mousePositionInScreen = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f); Vector3 mousePositionInWorld = Camera.main.ScreenToWorldPoint(mousePositionInScreen); mousePositionInWorld = new Vector3(mousePositionInWorld.x, 0.0f, mousePositionInWorld.z); Vector3 positionToLook = mousePositionInWorld - theTransform.position; theTransform.localRotation = Quaternion.LookRotation(positionToLook.normalized, Vector3.up); } if (Input.GetButtonDown(fireAxis) && canFire) { foreach (Transform transform in weaponTransforms) { AmmoManager.SpawnAmmo(transform.position, transform.rotation); } canFire = false; Invoke("EnableFire", reloadDelay); } }
// Update is called once per frame void Update() { //firing turret if (Input.GetButtonDown(FireAxis) && CanFire) { AmmoManager.SpawnAmmo(transform.position, transform.rotation); } }
//public GameObject ammoPrefab = null; // Update is called once per frame void Update() { if (Input.GetButtonDown("Fire1")) { AmmoManager.SpawnAmmo(transform.position, transform.rotation); //Instantiate(ammoPrefab, transform.position, transform.rotation); } }
private void Shooting() { currentDeltaTime += Time.deltaTime; if (AmmoManager.instance.magazine > 0 && currentDeltaTime >= timeDelay && Input.GetMouseButtonDown(0)) { AmmoManager.SpawnAmmo(transform.position, transform.rotation); currentDeltaTime = 0f; } }
/// <summary> /// Function that instanciate the amunition prefab whenever the player press fire1 /// </summary> private void SpawnAmmo() { if (Input.GetButtonDown("Fire1")) { //Instantiate(ammunition, transform.position,transform.rotation); //we now go through the ammomanager instead of instanciating ammunition into the scene via this function. AmmoManager.SpawnAmmo(transform.position, transform.rotation); } }
void FixedUpdate() { if (Input.GetKey(KeyCode.Space) && canFire) { AudioSource.PlayClipAtPoint(laserAudio, transform.position); AmmoManager.SpawnAmmo(transform.position, transform.rotation); canFire = false; Invoke("EnableFire", reloadDelay); } }
// Update is called once per frame void FixedUpdate() { if (Input.GetButtonDown(fireAxis) && canFire) { foreach (Transform t in turretTransforms) { AmmoManager.SpawnAmmo(t.position, t.rotation); } canFire = false; Invoke("EnableFire", reloadDelay); } }
// Update is called once per frame void Update() { //Check fire control if (Input.GetButtonDown("Fire1") && CanFire) { foreach (Transform T in TurretTransforms) { AmmoManager.SpawnAmmo(T.position, T.rotation); } CanFire = false; Invoke("EnableFire", ReloadDelay); } }
//------------------------------ // Update is called once per frame void Update() { //Update movement float Horz = Input.GetAxis(HorzAxis); float Vert = Input.GetAxis(VertAxis); Vector3 MoveDirection = new Vector3(Horz, 0.0f, Vert); ThisBody.AddForce(MoveDirection.normalized * MaxSpeed); //Clamp speed ThisBody.velocity = new Vector3(Mathf.Clamp(ThisBody.velocity.x, -MaxSpeed, MaxSpeed), Mathf.Clamp(ThisBody.velocity.y, -MaxSpeed, MaxSpeed), Mathf.Clamp(ThisBody.velocity.z, -MaxSpeed, MaxSpeed)); //Should look with mouse? if (MouseLook) { //Update rotation - turn to face mouse pointer Vector3 MousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f)); MousePosWorld = new Vector3(MousePosWorld.x, 0.0f, MousePosWorld.z); //Get direction to cursor Vector3 LookDirection = MousePosWorld - ThisTransform.position; //FixedUpdate rotation ThisTransform.localRotation = Quaternion.LookRotation(LookDirection.normalized, Vector3.up); } if (Input.GetButtonDown(FireAxis) && CanFire) { foreach (Transform T in TurretTransforms) { AmmoManager.SpawnAmmo(T.position, T.rotation); Debug.Log("Ammo fired"); } CanFire = false; Invoke("EnableFire", ReloadDelay); } if (Input.GetButtonDown(ModeAxis)) { ChangeModes(); } }
void FixedUpdate() { //Actualizar el movimiento float horizontal = Input.GetAxis(horizontalAxis); //valor entre -1 y 1 float vertical = Input.GetAxis(verticalAxis); Vector3 direction = new Vector3(horizontal, 0, vertical); theBody.AddForce(direction.normalized * maxSpeed); //Actualizar la velocidad theBody.velocity = new Vector3( Mathf.Clamp(theBody.velocity.x, -maxSpeed, maxSpeed), Mathf.Clamp(theBody.velocity.y, -maxSpeed, maxSpeed), Mathf.Clamp(theBody.velocity.z, -maxSpeed, maxSpeed) ); //Rotación de la nave con ratón if (mouseLook) { Vector3 mousePositionInScreen = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f); Vector3 mousePositionInWorld = Camera.main.ScreenToWorldPoint(mousePositionInScreen); mousePositionInWorld = new Vector3(mousePositionInWorld.x, 0.0f, mousePositionInWorld.z); Vector3 positionToLook = mousePositionInWorld - theTransform.position; theTransform.localRotation = Quaternion.LookRotation(positionToLook.normalized, Vector3.up); } //Chequear el disparo de la nave if (Input.GetButtonDown(fireAxis) && canFire) { foreach (Transform t in weaponTransforms) { AmmoManager.SpawnAmmo(t.position, t.rotation); } canFire = false; Invoke("EnableFire", reloadDelay); } }
//[PunRPC] void ShootBullet(Vector3 Pos, Quaternion quaat){ // GameObject GO = Instantiate(Bullet, Pos, quaat) as GameObject; // GO.GetComponent<Rigidbody>().velocity = transform.TransformDirection(Vector3.forward * force); //} [PunRPC] void ShootBullet() { //Instantiate(AmmoPrefab, transform.position, transform.rotation); AmmoManager.SpawnAmmo(transform.position, transform.rotation); }
//------------------------------------- void FixedUpdate() { //Update movement //Mobile Code /*float Horz = CrossPlatformInputManager.GetAxis("Horizontal"); * float Vert = CrossPlatformInputManager.GetAxis("Vertical");*/ //keyboard controlls float Horz = Input.GetAxis(HorzAxis); float Vert = Input.GetAxis(VertAxis); Vector3 MoveDirection = new Vector3(Horz, 0f, Vert); ThisBody.AddForce(MoveDirection.normalized * MaxSpeed); //Clamp speed ThisBody.velocity = new Vector3 (Mathf.Clamp(ThisBody.velocity.x, -MaxSpeed, MaxSpeed), Mathf.Clamp(ThisBody.velocity.y, -MaxSpeed, MaxSpeed), Mathf.Clamp(ThisBody.velocity.z, -MaxSpeed, MaxSpeed)); //should look with mouse if (MouseLook) { //Update rotation - turn to face mouse pointer //Keyboard controlls Vector3 MousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f)); MousePosWorld = new Vector3(MousePosWorld.x, 0.0f, MousePosWorld.z); //Get direction to cursor Vector3 LookDirection = MousePosWorld - ThisTransform.position; //FixedUpdate rotation ThisTransform.localRotation = Quaternion.LookRotation(LookDirection.normalized, Vector3.up); //Mobile Code //ThisTransform.localRotation = Quaternion.LookRotation(MoveDirection.normalized, Vector3.up); bool fireButton = CrossPlatformInputManager.GetButton("Fire"); } //Check fire control /*Spacebar is used for mobile controls to shoot * if(Input.GetKeyDown(KeyCode.Space)&&CanFire) * { * foreach (Transform T in TurretTransforms) * AmmoManager.SpawnAmmo(T.position, T.rotation); * * CanFire = false; * Invoke("EnableFire", ReloadDelay); * } */ if (Input.GetButtonDown(FireAxis) && CanFire) { foreach (Transform T in TurretTransforms) { AmmoManager.SpawnAmmo(T.position, T.rotation); } CanFire = false; Invoke("EnableFire", ReloadDelay); } }