- Home /
Line Renderer methods not found?
Hello. I am trying to make a simple line with the line renderer (my first time). But when i try to add the .set functions, there are none available. I have added a the line renderer to a gameobject (same as the script is applied to).
I tried copy pasting the codes from the Unity example: http://docs.unity3d.com/Documentation/ScriptReference/LineRenderer.SetPosition.html
My code looks like this:
using UnityEngine;
using System.Collections;
public class LineRenderer : MonoBehaviour {
public Transform startpoint;
public Transform endpoint;
public Color c1 = Color.yellow;
public Color c2 = Color.red;
public int lengthOfLineRenderer = 20;
// Use this for initialization
void Start () {
LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
lineRenderer.SetColors(c1, c2);
lineRenderer.SetWidth(0.2F, 0.2F);
lineRenderer.SetVertexCount(lengthOfLineRenderer);
}
// Update is called once per frame
void Update () {
LineRenderer lineRenderer = GetComponent<LineRenderer>();
int i = 0;
while (i < lengthOfLineRenderer) {
Vector3 pos = new Vector3(i * 0.5F, Mathf.Sin(i + Time.time), 0);
lineRenderer.SetPosition(i, pos);
i++;
}
}
}
This is what the error says:
Assets/Script/LineRenderer.cs(16,30): error CS1061: Type LineRenderer' does not contain a definition for
material' and no extension method material' of type
LineRenderer' could be found (are you missing a using directive or an assembly reference?)
here is a screenshot of the available choices:
Answer by aldonaletto · Nov 21, 2013 at 11:00 PM
You've violated one of Unity commandments:
Thou shalt never save a script with the same name of any Unity class
Since you've saved the script as LineRenderer, a new class named LineRenderer was created and hid the original LineRenderer. Save the script with another name (and remember to rename the class declaration accordingly, and also to delete the old script) - for instance:
using UnityEngine;
using System.Collections;
public class LineRendererScript : MonoBehaviour {
...
Save the script as LineRendererScript.cs, then delete the old LineRenderer.cs
Oh, thank you! I will remember that! Ive used unity for a week now, so I'm sorry I've missed that law. Thanks for the help!
It's actually a general law ;) If you implement a new version of a class that would hide another one with the same name.
Your answer
Follow this Question
Related Questions
LineRenderer. Smooth corners. 1 Answer
LineRenderer not showing the correct color 0 Answers
Linerenderer view rotation in local space 1 Answer
Line renderer from UI to 3D GameObject 0 Answers
BeamWeapon Does not damage target 0 Answers