Advertisement
CakeMeister

Moving Plat

Jun 26th, 2017
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovingPlat : MonoBehaviour {
  6.  
  7.     public float speed = 0.05f, changeDirection = -1;
  8.     Vector3 Move;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.         Move = this.transform.position;
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         Move.x += speed;
  18.         this.transform.position = Move;
  19.  
  20.     }
  21.  
  22.     private void OnCollisionEnter2D(Collision2D col)
  23.     {
  24.         if (col.collider.CompareTag("Ground"))
  25.         {
  26.             speed *= changeDirection;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement