jangio14

Le codigo

Nov 13th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. //
  2.  
  3. Quiero que shotSpawnL y shotSpawnR se disparen a la vez :/ Con el mismo botón o con Fire1 el L y Fire2 el R
  4.  
  5. //
  6.  
  7.  
  8. using UnityEngine;
  9. using System.Collections;
  10.  
  11. [System.Serializable]
  12. public class Boundary
  13. {
  14. public float xMin, xMax, zMin, zMax;
  15. }
  16.  
  17. public class PlayerController : MonoBehaviour
  18. {
  19. public float speed;
  20. public float tilt;
  21. public Boundary boundary;
  22. public GameObject shot;
  23. public Transform shotSpawnL;
  24. public Transform shotSpawnR;
  25. public float fireRate;
  26.  
  27. private float nextFire;
  28.  
  29. void Update ()
  30. {
  31. if (Input.GetButton("Fire1") && Time.time > nextFire)
  32. {
  33. nextFire = Time.time + fireRate;
  34.  
  35. GameObject clone = Instantiate(shot, shotSpawnL.position, shotSpawnL.rotation) as GameObject;
  36. audio.Play ();
  37. }
  38.  
  39. if (Input.GetButton("Fire2") && Time.time > nextFire)
  40. {
  41. nextFire = Time.time + fireRate;
  42.  
  43. GameObject clone = Instantiate(shot, shotSpawnR.position, shotSpawnR.rotation) as GameObject;
  44. audio.Play ();
  45. }
  46. }
  47.  
  48. void FixedUpdate()
  49. {
  50. float moveHorizontal = Input.GetAxis ("Horizontal");
  51. float moveVertical = Input.GetAxis ("Vertical");
  52.  
  53. Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
  54. rigidbody.velocity = movement * speed;
  55.  
  56. rigidbody.position = new Vector3
  57. (
  58. Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
  59. 0.0f,
  60. Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
  61. );
  62.  
  63. rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment