I am making a game but thre is a problem with my line renderer here is the code. The problem is that on line 48 of playermove script it says there is no object reference
PowerLine Script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PowerLine : MonoBehaviour
{
// public
public LineRenderer lr;
// void
void Awake()
{
lr = GetComponent<LineRenderer>();
}
public void RenderLine(Vector3 startPoint, Vector3 endPoint)
{
lr.positionCount = 2;
Vector3[] Linepoints = new Vector3[2];
Linepoints[0] = startPoint;
Linepoints[1] = endPoint;
lr.SetPositions(Linepoints);
}
public void EndLine()
{
lr.positionCount = 0;
}
}
playermove script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
// public
public float power = 10f;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
PowerLine pl;
// private
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
// void
void Start()
{
cam = Camera.main;
pl = GetComponent<PowerLine>();
}
void Update()
{
if (Input.simulateMouseWithTouches)
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.simulateMouseWithTouches)
{
Vector3 currentPoint = cam.ScreenToWorldPoint(Input.mousePosition);
currentPoint.z = 15;
pl.RenderLine(startPoint, currentPoint);
}
if (Input.simulateMouseWithTouches)
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
pl.EndLine();
}
}
}