Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GroundDown : MonoBehaviour {
  6.     public float height = 1.0f;
  7.     void Update () {
  8.         RaycastHit hit;
  9.         Vector3 pos = new Vector3 ( transform.position.x, transform.position.y + height, transform.position.z );
  10.         if ( Physics.Raycast ( pos, -Vector3.up, out hit ) ) {
  11.             if ( hit.distance - height < 0.0f ) {
  12.                 transform.position = hit.point;
  13.             } else if ( hit.distance - height > 0.1f ) {
  14.                 transform.position -= Vector3.up * 0.1f;
  15.             }
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement