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

using UnityEngine;
using System.Collections;
public class MagnetLaser : MonoBehaviour {
private LineRenderer lr;
public GameObject player;
public GameObject rodStart;
public GameObject magnetSparkles;
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) {
if (magnetSparkles != null)
magnetSparkles.SetActive(true);
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;
if (magnetSparkles != null)
magnetSparkles.SetActive(false);
}
}
}