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.

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