vitorfgd

BulletBehavior

Jan 25th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BulletBehavior : MonoBehaviour {
  5.  
  6. private float speed = 5f;
  7. public float rotationSpeed;
  8. private Transform myTrans;
  9. private Vector3 myPos, myRot;
  10. private float angle;
  11.  
  12. void Start (){
  13. myTrans = transform;
  14. myPos = myTrans.position;
  15. myRot = myTrans.rotation.eulerAngles;
  16. }
  17.  
  18. void FixedUpdate () {
  19.  
  20. angle = myTrans.eulerAngles.magnitude * Mathf.Deg2Rad;
  21.  
  22. if (Input.GetKey (KeyCode.RightArrow)) {
  23. myRot.z -= rotationSpeed;
  24. }
  25. if (Input.GetKey (KeyCode.LeftArrow)) {
  26. myRot.z += rotationSpeed;
  27. }
  28.  
  29. if (Input.GetKey (KeyCode.UpArrow)) {
  30.  
  31. myPos.x += (Mathf.Cos (angle) * speed) * Time.deltaTime;
  32. myPos.y += (Mathf.Sin (angle) * speed) * Time.deltaTime;
  33. }
  34.  
  35. if (Input.GetKey (KeyCode.DownArrow)) {
  36. myPos.x += Mathf.Cos (angle) * Time.deltaTime;
  37. myPos.y += Mathf.Sin (angle) * Time.deltaTime;
  38. }
  39.  
  40. myTrans.position = myPos;
  41. myTrans.rotation = Quaternion.Euler (myRot);
  42.  
  43. }
  44. }
Add Comment
Please, Sign In to add comment