- Home /
The referenced script on this Behavior ( Game Object 'Camera') is missing. What shall I do?
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;
}
}
Assu$$anonymous$$g the error is on line 17. If not, where is it? The error message should give a line number.
If so, is there a Camera script on the object you have the script attached to? It's not totally clear from your description.
Answer by Firestream1014 · Dec 16, 2017 at 07:40 PM
Not 100 percent sure if this works so I'm sorry if it doesn't but could try adding " Public Camera cam" to where you initiated your variables and "ray = cam.ScreenPointToRay(Input.mousePosition) " Hopefully, it works, sorry if I wasted you time :(
Yeah, that would be way more efficient but it would work only if the code already worked.
Follow this Question
Related Questions
Line Renderer Issues 1 Answer
Linerenderer doesn't match my ray. 1 Answer
Setting Line Render position directly forward from facing of game object 1 Answer
Bouncing Raycast "Laser" Not Working? 1 Answer
Multiple Cars not working 1 Answer