I keep getting this error on my script ive tried everything–
UnassignedReferenceException: The variable sightLine of ff has not been assigned. You probably need to assign the sightLine variable of the ff script in the inspector. UnityEngine.LineRenderer.SetColors (Color start, Color end) (at C:/buildslave/unity/build/artifacts/generated/common/runtime/GraphicsBindings.gen.cs:1365) ff.simulatePath () (at Assets/darts/ff.cs:89) ff.FixedUpdate () (at Assets/darts/ff.cs:26)
using UnityEngine;
/// <summary>
/// Controls the Laser Sight for the player's aim
5. /// </summary>
public class ff : MonoBehaviour
{
// Reference to the LineRenderer we will use to display the simulated path
public LineRenderer sightLine;
10.
// Reference to a Component that holds information about fire strength, location of cannon, etc.
public PlayerFire playerFire;
// Number of segments to calculate - more gives a smoother line
15. public int segmentCount = 20;
// Length scale for each segment
public float segmentScale = 1;
20. // gameobject we're actually pointing at (may be useful for highlighting a target, etc.)
private Collider _hitObject;
public Collider hitObject { get { return _hitObject; } }
void FixedUpdate()
25. {
simulatePath();
}
/// <summary>
30. /// Simulate the path of a launched ball.
/// Slight errors are inherent in the numerical method used.
/// </summary>
void simulatePath()
{
35. Vector3[] segments = new Vector3[segmentCount];
// The first line point is wherever the player's cannon, etc is
segments[0] = playerFire.transform.position;
40. // The initial velocity
Vector3 segVelocity = playerFire.transform.up * playerFire.fireStrength * Time.deltaTime;
// reset our hit object
_hitObject = null;
45.
for (int i = 1; i < segmentCount; i++)
{
// Time it takes to traverse one segment of length segScale (careful if velocity is zero)
float segTime = (segVelocity.sqrMagnitude != 0) ? segmentScale / segVelocity.magnitude : 0;
50.
// Add velocity from gravity for this segment's timestep
segVelocity = segVelocity + Physics.gravity * segTime;
// Check to see if we're going to hit a physics object
55. RaycastHit hit;
if (Physics.Raycast(segments[i - 1], segVelocity, out hit, segmentScale))
{
// remember who we hit
_hitObject = hit.collider;
60.
// set next position to the position where we hit the physics object
segments _= segments[i - 1] + segVelocity.normalized * hit.distance;_
// correct ending velocity, since we didn’t actually travel an entire segment
segVelocity = segVelocity - Physics.gravity * (segmentScale - hit.distance) / segVelocity.magnitude;
65. // flip the velocity to simulate a bounce
segVelocity = Vector3.Reflect(segVelocity, hit.normal);
/*
* Here you could check if the object hit by the Raycast had some property - was
70. * sticky, would cause the ball to explode, or was another ball in the air for
* instance. You could then end the simulation by setting all further points to
* this last point and then breaking this for loop.
*/
}
75. // If our raycast hit no objects, then set the next position to the last one plus v*t
else
{
segments = segments[i - 1] + segVelocity * segTime;
}
80. }
// At the end, apply our simulations to the LineRenderer
// Set the colour of our path to the colour of the next ball
85. Color startColor = playerFire.nextColor;
Color endColor = startColor;
startColor.a = 1;
endColor.a = 0;
sightLine.SetColors(startColor, endColor);
90.
sightLine.SetVertexCount(segmentCount);
for (int i = 0; i < segmentCount; i++)
sightLine.SetPosition(i, segments*);*
}
95. }