code needed to draw with line renderer by following mouse
I have attached script(called ‘‘script’’) and line Renderer to Camera
but it doesn’t draw and show this mistake “The referenced script on this Behavior ( Game Object ‘Camera’) is missing”
Here is the code:
using UnityEngine;
using System.Collections;
public class Draw :
MonoBehaviour {
RaycastHit hit;
string dtxt;
bool mouseIsDown = false;
LineRenderer lineRender;
int numberOfPoints = 0;
void Start (){
}
void Update (){
Ray ray = new Ray(transform.position, transform.forward);
ArrayList thePath = new ArrayList();
dtxt = "";
ray = GetComponent<Camera>().ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, 1000)){
if (mouseIsDown) {
thePath.Add(hit.point);
lineRender.SetVertexCount( thePath.Count );
lineRender.SetPosition(thePath.Count - 1, hit.point+new Vector3(0,1,0));
}
}
if(Input.GetMouseButtonDown(0))
{
mouseIsDown = true;
}
if (Input.GetMouseButtonUp(0)){
mouseIsDown = false;
}
//transform.parent.gameObject.transform.eulerAngles.y += 0.2f;
}
}