You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class MagnetLaser : MonoBehaviour {
  4. private LineRenderer lr;
  5. public GameObject player;
  6. public GameObject rodstart;
  7. public int segments;
  8. public float randomSize;
  9. private magnetGun gun;
  10. private ParticleSystem[] sparks;
  11. // Use this for initialization
  12. void Start () {
  13. gun = player.GetComponent<magnetGun> ();
  14. lr = GetComponent<LineRenderer> ();
  15. sparks = gun.GetComponentsInChildren<ParticleSystem>();
  16. }
  17. // Update is called once per frame
  18. void Update () {
  19. if (gun.GravityTarget != null) {
  20. sparks[0].enableEmission = true;
  21. sparks[1].enableEmission = true;
  22. lr.enabled = true;
  23. lr.SetVertexCount(segments+1);
  24. lr.SetPosition(0, rodstart.transform.position);
  25. lr.SetPosition (segments,gun.GravityTarget.transform.position);
  26. Vector3 normalizedV =(gun.GravityTarget.transform.position - player.transform.position);
  27. float distance = normalizedV.magnitude;
  28. //normalizedV.Normalize();
  29. for (int i = 1; i<segments; i++){
  30. Debug.Log(i);
  31. Vector3 point = player.transform.position + (normalizedV/segments)*i;
  32. //startPos.y + (endPos.y - startPos.y) / dis
  33. point.x += Random.Range(-randomSize,randomSize);
  34. point.y += Random.Range(-randomSize,randomSize);
  35. point.z += Random.Range(-randomSize,randomSize);
  36. lr.SetPosition(i,point);
  37. }
  38. } else {
  39. lr.enabled = false;
  40. sparks[0].enableEmission = false;
  41. sparks[1].enableEmission = false;
  42. }
  43. }
  44. }