using UnityEngine;
|
|
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> ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
}
|
|
|
|
|
|
} else {
|
|
lr.enabled = false;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|