Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MoverShip01 : MonoBehaviour {
- //boundary lo utilizo para establecer limites de movimiento en la Ship01
- public Boundary boundary;
- public float speed;
- [Header("move left and right")]
- public float dodge;
- public float smothing;
- public Vector2 moveTime;
- public Vector2 moveWait;
- public Vector2 startWait;
- private float targetMove;
- // el giro sobre el eje Z que hara la nave
- public float tilt;
- //private bool stopShip1 = false;
- private Rigidbody rig;
- private void Awake()
- {
- rig = GetComponent<Rigidbody>();
- }
- // Use this for initialization
- void Start () {
- rig.velocity = transform.forward * speed;
- Vector3 positionShip = new Vector3(7.1f, rig.position.y, rig.position.z);
- }
- // Update is called once per frame
- void Update () {
- if (rig.position.z < 7.2)
- {
- stopShip();
- //Debug.Log("velocity: " +speed);
- }
- }
- private void FixedUpdate()
- {
- if (stopShip() == true)
- {
- targetMove = rig.position.x <= 0 ? 1 : -1;
- if (targetMove == 1)
- {
- while (rig.position.x <= 6.50)
- {
- Vector3 movement = new Vector3(1 * speed, 0f, 0f);
- rig.velocity = movement;
- rig.rotation = Quaternion.Euler(0f, 0f, rig.velocity.x * -tilt);
- Debug.Log(rig.position.x);
- }
- stopShip();
- }
- else if (targetMove == -1)
- {
- while (rig.position.x >= -6.50)
- {
- Vector3 movement = new Vector3(-1 * speed, 0f, 0f);
- rig.velocity = movement;
- rig.rotation = Quaternion.Euler(0f, 0f, rig.velocity.x * -tilt);
- Debug.Log(rig.position.x);
- }
- stopShip();
- }
- }
- }
- private bool stopShip()
- {
- //rig.isKinematic = true;
- rig.velocity = Vector3.zero;
- transform.rotation = Quaternion.identity;
- return true;
- }
- }
Add Comment
Please, Sign In to add comment