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: Unity - Scripting API: LineRenderer.SetPosition
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: 