Posted By

shen305 on 05/17/17


Tagged


Versions (?)

LightTest


 / Published in: C#
 

test

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MovingShadows : MonoBehaviour{
  5. public float windSpeedX;
  6. public float windSpeedZ;
  7. private float lightCookieSize;
  8. private Vector3 initPos;
  9.  
  10. void Start(){
  11. initPos = transform.position;?????????????//Light's unchanged position
  12. lightCookieSize = GetComponent<Light>().cookieSize;
  13. }
  14.  
  15. void Update(){
  16. Vector3 pos = transform.position; // Light's right now position
  17. float xPos= Mathf.Abs (pos.x); // absolute value of pos.x
  18. float zPos= Mathf.Abs (pos.z);
  19. float xLimit = Mathf.Abs(initPos.x) + lightCookieSize; //limit = absolute of unchanged position + cookieSize?
  20. float zLimit = Mathf.Abs(initPos.z) + lightCookieSize;
  21.  
  22. if (xPos >= xLimit) // if right now position of x >= xLimit, assign position of x unchanged pos.x
  23. pos.x = initPos.x;
  24.  
  25. if (zPos >= zLimit) // same to position of z
  26. pos.z = initPos.z;
  27.  
  28. transform.position = pos; // assign back the new pos value to light
  29. float windX = Time.deltaTime * windSpeedX; //wind's position change : deltaTime (1 frame time) * windSpeed
  30. float windZ = Time.deltaTime * windSpeedZ;
  31. transform.Translate(windX, 0, windZ, Space.World); //assign value to light's transform translate.
  32. }
  33. }

Report this snippet  

You need to login to post a comment.