Advertisement
Guest User

MovementofObjects

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class KinamaticMovement : MonoBehaviour {
  6.  
  7.  
  8.     public float movementSpeed = 0.2f;
  9.     private bool isMovement;
  10.     // Use this for initialization
  11.     void Start () {
  12.         isMovement = true;
  13.     }
  14.    
  15.     // Update is called once per frame
  16.     void Update () {
  17.         if(isMovement == true)
  18.         {
  19.             movement();
  20.         }
  21.         if(isMovement == false)
  22.         {
  23.  
  24.         }
  25.     }
  26.  
  27.     void movement()
  28.     {
  29.         transform.Translate(movementSpeed * Time.deltaTime, 0f, 0f );
  30.     }
  31.  
  32.     void noMovement()
  33.     {
  34.        // Debug.Log("Executed no movement");
  35.         transform.Translate(0f, 0f, 0f);
  36.     }
  37.  
  38.     void OnTriggerEnter(Collider other)
  39.     {
  40.          //  Debug.Log("Collision detected");
  41.         if(other.gameObject.CompareTag("Plate"))
  42.         {
  43.             Destroy(this.gameObject);
  44.             //  Debug.Log("object destroyed");
  45.         }
  46.  
  47.         if(other.gameObject.CompareTag("Ground"))
  48.         {
  49.             //  Debug.Log("object collision with ground");
  50.             isMovement = false;
  51.             Destroy(this.gameObject);
  52.             noMovement();
  53.            
  54.         }
  55.     }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement