Advertisement
Guest User

CloudShadow for Unity3d

a guest
Jul 20th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class CloudShadow : MonoBehaviour
  4. {
  5.     #region Fields
  6.     private GameObject sun;
  7.     private Projector cloudShadow;
  8.     private RaycastHit hit;
  9.     #endregion
  10.  
  11.     void Start ()
  12.     {
  13.         // Find your sunlight by it's name
  14.         sun = GameObject.Find("Sunlight");
  15.         cloudShadow = GetComponentInParent<Projector>();
  16.     }
  17.  
  18.     void Update ()
  19.     {
  20.         // Cast a Raycast from the cloud to the sun's direction
  21.         if(Physics.Raycast (transform.parent.position, sun.transform.forward, out hit))
  22.         {
  23.             // Height is fixed at 1000 as it fits my game - apply what you need
  24.             transform.position = new Vector3(hit.point.x, 1000f, hit.point.z);
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement