Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// Key movement. Que mueva un objeto cuando se pulsen teclas
- /// </summary>
- public class Controller : MonoBehaviour {
- public float speed =5.0f;
- public float angularSpeed = 50.0f;
- public float angularSpeedCal = 15.0f;
- public GameObject calibrator;
- public GameObject barcaza;
- public GameObject torreta;
- public float bulletSpeed =500.0f;
- public GameObject missile;
- private float fuerzaDisparo;
- private bool disparando;
- private bool dispara;
- // Use this for initialization
- void Start ()
- {
- fuerzaDisparo = 0.0f;
- disparando = false;
- dispara = false;
- }
- // Update is called once per frame
- void Update ()
- {
- //transform.position += Vector3.one * speed * Time.deltaTime;
- //Aki se mueve la barcaza del tanke
- if (Input.GetKey (KeyCode.UpArrow))
- {
- transform.position += transform.forward * speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.DownArrow))
- {
- transform.position -= transform.forward * speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.LeftArrow))
- {
- transform.Rotate(new Vector3(0, -angularSpeed * Time.deltaTime, 0));
- }
- if (Input.GetKey (KeyCode.RightArrow))
- {
- transform.Rotate(new Vector3(0, angularSpeed * Time.deltaTime, 0));
- }
- //Aki se mueve el calibrador
- if (Input.GetKey (KeyCode.W))
- {
- if(calibrator.transform.rotation.x > -0.31f)
- calibrator.transform.Rotate(new Vector3(-angularSpeedCal * Time.deltaTime, 0, 0));
- }
- else if (Input.GetKey (KeyCode.S))
- {
- if(calibrator.transform.rotation.x < 0.31f)
- calibrator.transform.Rotate(new Vector3(angularSpeedCal * Time.deltaTime, 0 , 0));
- }
- //Aki se mueve la torreta
- else if (Input.GetKey (KeyCode.A))
- {
- torreta.transform.Rotate(new Vector3( 0,-angularSpeedCal * Time.deltaTime, 0));
- }
- else if (Input.GetKey (KeyCode.D))
- {
- torreta.transform.Rotate(new Vector3( 0,angularSpeedCal * Time.deltaTime, 0));
- }
- //Debug.Log (calibrator.transform.rotation.x);
- //Debug.Log (torreta.transform.rotation.x);
- //El disparo del artefacto
- if(Input.GetKeyDown(KeyCode.Space))
- {
- if (disparando == true && dispara == false)
- {
- dispara = true;
- disparando = false;
- }
- else if (disparando == false)
- disparando = true;
- }
- if (disparando && !dispara)
- {
- fuerzaDisparo += Time.deltaTime;
- //Debug.Log (fuerzaDisparo);
- }
- if (dispara)
- {
- GameObject bulletObject = Instantiate(missile, calibrator.transform.position + transform.forward *1, Quaternion.identity) as GameObject;
- ShootBullet( bulletObject, Mathf.Clamp(fuerzaDisparo,1.0f,2.5f));
- dispara = false;
- fuerzaDisparo = 0.0f;
- }
- }
- public void ShootBullet(GameObject bulletObject, float fd)
- {
- //Este metodo Dispara las balas
- Rigidbody bulletRigidbody = bulletObject.rigidbody;
- bulletRigidbody.AddForce(calibrator.transform.forward * bulletSpeed * fd);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement