Advertisement
dimon-torchila

Untitled

Feb 28th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Redcode.Moroutines;
  4. using Redcode.Extensions;
  5. using UnityEngine;
  6.  
  7. public class RollerMovement : MonoBehaviour
  8. {
  9. private GameController controller;
  10. private Dictionary<GameObject, Moroutine> _moving_objects;
  11. void Start()
  12. {
  13. _moving_objects = new Dictionary<GameObject, Moroutine>();
  14. controller = GameObject.FindObjectOfType<GameController>();
  15. }
  16.  
  17. void OnTriggerEnter(Collider other) {
  18. if (other.tag != "Item")
  19. return;
  20. _moving_objects[other.gameObject] = Moroutine.Run(Routines.Repeat(-1, Routines.Delay(0, () =>
  21. {
  22. other.attachedRigidbody.AddForce(new Vector3(controller.speed - other.attachedRigidbody.velocity.x, 0, 0),
  23. ForceMode.VelocityChange);
  24. })));
  25. }
  26.  
  27. void OnTriggerExit(Collider other) {
  28. if (other.tag != "Item")
  29. return;
  30. _moving_objects[other.gameObject].Stop();
  31. _moving_objects.Remove(other.gameObject);
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement