Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ScrollingObject : MonoBehaviour
  6. {
  7. private Rigidbody2D rb2d;
  8. public float scrollSpeed = -1.5f;
  9.  
  10. // Use this for initialization
  11. void Start()
  12. {
  13. //Get and store a reference to the Rigidbody2D attached to this GameObject.
  14. rb2d = GetComponent<Rigidbody2D>();
  15.  
  16. //Start the object moving.
  17. rb2d.velocity = new Vector2(scrollSpeed, 0);
  18. }
  19.  
  20. void Update()
  21. {
  22. // If the game is over, stop scrolling.
  23. if (Obstacle.CollideWithAsteroid) // bool that determines if the game ends
  24. {
  25. rb2d.velocity = Vector2.zero;
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement