|
|
@ -4,11 +4,18 @@ using System.Collections; |
|
|
|
public class MagnetLaser : MonoBehaviour { |
|
|
|
|
|
|
|
private LineRenderer lr; |
|
|
|
public GameObject player; |
|
|
|
public GameObject rodstart; |
|
|
|
public int segments; |
|
|
|
public float randomSize; |
|
|
|
private magnetGun gun; |
|
|
|
|
|
|
|
|
|
|
|
// Use this for initialization
|
|
|
|
void Start () { |
|
|
|
gun = player.GetComponent<magnetGun> (); |
|
|
|
lr = GetComponent<LineRenderer> (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -17,24 +24,37 @@ public class MagnetLaser : MonoBehaviour { |
|
|
|
// Update is called once per frame
|
|
|
|
void Update () { |
|
|
|
|
|
|
|
if (gun.GravityTarget != null) { |
|
|
|
lr.enabled = true; |
|
|
|
lr.SetVertexCount(segments+1); |
|
|
|
lr.SetPosition(0, rodstart.transform.position); |
|
|
|
lr.SetPosition (segments,gun.GravityTarget.transform.position); |
|
|
|
|
|
|
|
Vector3 normalizedV =(gun.GravityTarget.transform.position - player.transform.position); |
|
|
|
float distance = normalizedV.magnitude; |
|
|
|
//normalizedV.Normalize();
|
|
|
|
for (int i = 1; i<segments; i++){ |
|
|
|
Debug.Log(i); |
|
|
|
Vector3 point = player.transform.position + (normalizedV/segments)*i; |
|
|
|
//startPos.y + (endPos.y - startPos.y) / dis
|
|
|
|
|
|
|
|
point.x += Random.Range(-randomSize,randomSize); |
|
|
|
point.y += Random.Range(-randomSize,randomSize); |
|
|
|
point.z += Random.Range(-randomSize,randomSize); |
|
|
|
|
|
|
|
lr.SetPosition(i,point); |
|
|
|
} |
|
|
|
|
|
|
|
// Magnet Laser Collision
|
|
|
|
RaycastHit hit; |
|
|
|
|
|
|
|
if (Physics.Raycast (transform.position, transform.forward, out hit)) { |
|
|
|
} else { |
|
|
|
lr.enabled = false; |
|
|
|
} |
|
|
|
|
|
|
|
if(hit.collider){ |
|
|
|
lr.SetPosition(1,new Vector3(0,0,hit.distance)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else{ |
|
|
|
lr.SetPosition(1,new Vector3(0,0,100)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |