Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using Redcode.Moroutines;
- using Redcode.Extensions;
- using UnityEngine;
- public class RollerMovement : MonoBehaviour
- {
- private GameController controller;
- private Dictionary<GameObject, Moroutine> _moving_objects;
- void Start()
- {
- _moving_objects = new Dictionary<GameObject, Moroutine>();
- controller = GameObject.FindObjectOfType<GameController>();
- }
- void OnTriggerEnter(Collider other) {
- if (other.tag != "Item")
- return;
- _moving_objects[other.gameObject] = Moroutine.Run(Routines.Repeat(-1, Routines.Delay(0, () =>
- {
- other.attachedRigidbody.AddForce(new Vector3(controller.speed - other.attachedRigidbody.velocity.x, 0, 0),
- ForceMode.VelocityChange);
- })));
- }
- void OnTriggerExit(Collider other) {
- if (other.tag != "Item")
- return;
- _moving_objects[other.gameObject].Stop();
- _moving_objects.Remove(other.gameObject);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement