Stardog

Blob Shadow

Jul 20th, 2015
1,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BlobShadowScript : MonoBehaviour {
  5.  
  6.     [Header("Settings")]
  7.     public Transform blobShadowParent; // Parent GameObject with child (child is square mesh with shadow texture)
  8.     public Vector3 blobShadowParentOffset = new Vector3(0f, 0.01f, 0f);
  9.     public LayerMask layerMask;
  10.  
  11.     void Update()
  12.     {
  13.         Ray ray = new Ray(transform.position, -Vector3.up);
  14.         RaycastHit hitInfo;
  15.  
  16.         if (Physics.Raycast(ray, out hitInfo, 100f, layerMask))
  17.         {
  18.             blobShadowParent.position = hitInfo.point + blobShadowParentOffset;
  19.             blobShadowParent.up = hitInfo.normal;
  20.         }
  21.         else
  22.         {
  23.             blobShadowParent.position = hitInfo.point + new Vector3(0f, 1000f, 0f);
  24.         }
  25.     }
  26. }
Add Comment
Please, Sign In to add comment