onzulin

Untitled

Oct 15th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. public class MoverShip01 : MonoBehaviour {
  2.  
  3.     //boundary lo utilizo para establecer limites de movimiento en la Ship01
  4.     public Boundary boundary;
  5.     public float speed;
  6.     [Header("move left and right")]
  7.     public float dodge;
  8.     public float smothing;
  9.     public Vector2 moveTime;
  10.     public Vector2 moveWait;
  11.     public Vector2 startWait;
  12.     private float targetMove;
  13.     // el giro sobre el eje Z que hara la nave
  14.     public float tilt;
  15.     //private bool stopShip1 = false;
  16.     private Rigidbody rig;
  17.    
  18.    
  19.     private void Awake()
  20.     {
  21.         rig = GetComponent<Rigidbody>();
  22.     }
  23.     // Use this for initialization
  24.     void Start () {
  25.         rig.velocity = transform.forward * speed;
  26.         Vector3 positionShip = new Vector3(7.1f, rig.position.y, rig.position.z);
  27.        
  28.  
  29.     }
  30.    
  31.     // Update is called once per frame
  32.     void Update () {
  33.         if (rig.position.z < 7.2)
  34.         {
  35.              stopShip();  
  36.             //Debug.Log("velocity: " +speed);
  37.         }
  38.     }
  39.  
  40.     private void FixedUpdate()
  41.     {
  42.         if (stopShip() == true)
  43.         {
  44.             targetMove = rig.position.x <= 0 ? 1 : -1;
  45.             if (targetMove == 1)
  46.             {
  47.                 while (rig.position.x <= 6.50)
  48.                 {
  49.                     Vector3 movement = new Vector3(1 * speed, 0f, 0f);
  50.                     rig.velocity = movement;
  51.                     rig.rotation = Quaternion.Euler(0f, 0f, rig.velocity.x * -tilt);
  52.                     Debug.Log(rig.position.x);
  53.                 }
  54.                 stopShip();
  55.             }
  56.             else if (targetMove == -1)
  57.             {
  58.                 while (rig.position.x >= -6.50)
  59.                 {
  60.                     Vector3 movement = new Vector3(-1 * speed, 0f, 0f);
  61.                     rig.velocity = movement;
  62.                     rig.rotation = Quaternion.Euler(0f, 0f, rig.velocity.x * -tilt);
  63.                     Debug.Log(rig.position.x);
  64.                 }
  65.                 stopShip();
  66.             }
  67.         }
  68.        
  69.  
  70.     }
  71.    
  72.     private bool stopShip()
  73.     {
  74.         //rig.isKinematic = true;
  75.         rig.velocity = Vector3.zero;
  76.         transform.rotation = Quaternion.identity;
  77.         return true;
  78.     }
  79. }
Add Comment
Please, Sign In to add comment