I was wanting to convert a js script over to C# and for the most part its done but I have one line giving me problems please help.
using UnityEngine;
using System.Collections;
public class Lightning : MonoBehaviour {
public GameObject target;
public LineRenderer LR;
public double arcLength = 2.0;
public double arcVariation = 2.0;
public double inaccuracy = 1.0;
void Update()
{
Vector3 lastPoint = transform.position;
int i = 1;
LR.SetPosition(0, transform.position);//make the origin of the LR the same as the transform
while (Vector3.Distance(target.transform.position, lastPoint) >.5)
{//was the last arc not touching the target?
LR.SetVertexCount(i + 1);//then we need a new vertex in our line renderer
public fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc20.
fwd.Normalize();//makes the direction to scale
fwd = Randomize(fwd, inaccuracy);//we don't want a straight line to the target though
fwd *= Random.Range(arcLength * arcVariation, arcLength);//nature is never too uniform
fwd += lastPoint;//point + distance * direction = new point. this is where our new arc ends
LR.SetPosition(i, fwd);//this tells the line renderer where to draw to25.
i++;
lastPoint = fwd;//so we know where we are starting from for the next arc
}
}
The line with the problem is
public fwd = target.transform.position - lastPoint;//gives the direction to our target from the end of the last arc20.
If needed I can post the js version I was working from.
You're missing the type for
– Graham-Dunnettfwd. BTW, why not post the errors that the compiler gives you, or take a screenshot or something like that. We're all helpful over here, but at least try and give us something to work with. I'd have retired by now if I charged $1 to answer a compile problem where the questioner hasn't given the line number or the compiler error. :-)Also next time hit this site to take a look at any line you have issues with: http://files.m2h.nl/js_to_c.php
– drawcode