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.

67 lines
1.4 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 GameObject magnetSparkles;
  8. public int segments;
  9. public float randomSize;
  10. private magnetGun gun;
  11. // Use this for initialization
  12. void Start () {
  13. gun = player.GetComponent<magnetGun> ();
  14. lr = GetComponent<LineRenderer> ();
  15. }
  16. // Update is called once per frame
  17. void Update () {
  18. if (gun.GravityTarget != null) {
  19. if (magnetSparkles != null)
  20. magnetSparkles.SetActive(true);
  21. lr.enabled = true;
  22. lr.SetVertexCount(segments+1);
  23. lr.SetPosition(0, rodStart.transform.position);
  24. lr.SetPosition (segments,gun.GravityTarget.transform.position);
  25. Vector3 normalizedV =(gun.GravityTarget.transform.position - player.transform.position);
  26. float distance = normalizedV.magnitude;
  27. //normalizedV.Normalize();
  28. for (int i = 1; i<segments; i++){
  29. Debug.Log(i);
  30. Vector3 point = player.transform.position + (normalizedV/segments)*i;
  31. //startPos.y + (endPos.y - startPos.y) / dis
  32. point.x += Random.Range(-randomSize,randomSize);
  33. point.y += Random.Range(-randomSize,randomSize);
  34. point.z += Random.Range(-randomSize,randomSize);
  35. lr.SetPosition(i,point);
  36. }
  37. } else {
  38. lr.enabled = false;
  39. if (magnetSparkles != null)
  40. magnetSparkles.SetActive(false);
  41. }
  42. }
  43. }